<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../../assets/xml/rss.xsl" media="all"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><title>Josh Bialkowski (Publicaciones sobre Java Discoveries and Notes)</title><link>https://www.joshbialkowski.com/</link><description></description><atom:link href="https://www.joshbialkowski.com/es/categories/java-discoveries-and-notes.xml" rel="self" type="application/rss+xml"></atom:link><language>es</language><copyright>Contents © 2018 &lt;a href="mailto:josh.bialkowski@gmail.com"&gt;Josh Bialkowski&lt;/a&gt; 
&lt;a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"&gt;
&lt;img alt="Creative Commons License" style="border-width:0"
 src="https://i.creativecommons.org/l/by-sa/4.0/88x31.png" /&gt;
&lt;/a&gt;&lt;br /&gt;
This work is licensed under a
&lt;a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"&gt;
Creative Commons Attribution-ShareAlike 4.0 International License&lt;/a&gt;.
</copyright><lastBuildDate>Tue, 20 Mar 2018 01:48:00 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>HTML Documentation with Equation Numbers (Referencing an External PDF Document with Doxygen's HTML Documentation)</title><link>https://www.joshbialkowski.com/es/posts/2010/html-documentation-with-equation-numbers-referencing-an-external-pdf-document-with-doxygens-html-documentation.html</link><dc:creator>Josh Bialkowski</dc:creator><description>&lt;div&gt;&lt;p&gt;So, anyone who uses Doxygen to document their code knows that it's pretty much
the most amazing thing ever. Seriously, it's awesome. One cool thing about it
is the ability to reference external documentation. For instance, if you use a
library in your code and you want to include the library's documentation with
your own. However, let's say that (hypothetically of course) you're an
academic… and the code you write implements some theoretical design or model.
In that case, you may actually want your documentation to reference a paper,
or a report that you've written. Perhaps, even many such papers or reports.&lt;/p&gt;
&lt;h4&gt;The Problem&lt;/h4&gt;
&lt;p&gt;In particular, let's say that you're a grad student, in the process of writing
a paper (and of course, you used LaTex… because, well, why wouldn't you?) and
you go and write some code to simulate or demonstrate some elements of that
paper. In that case, some of your functions may implement certain equations.
Some of your classes (if it's object oriented) may implement certain models.
For an example, lets say this is your paper:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://www.joshbialkowski.com/es/posts/2010/wp-content/manual/01/dummy.png"&gt;&lt;/p&gt;
&lt;p&gt;Let's also assume that you've been good, and have been documenting your code
with Doxygen. Let's say you had some c++ class that implemented your model and
it's definition looks something like this:&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="cm"&gt;/**&lt;/span&gt;
&lt;span class="cm"&gt; *  file       CTheoreticalModel.h&lt;/span&gt;
&lt;span class="cm"&gt; *  author     Joe Author (jauthor@institute.edu)&lt;/span&gt;
&lt;span class="cm"&gt; *  date       Apr 17, 2010&lt;/span&gt;
&lt;span class="cm"&gt; *  brief      Definition file for CTheoreticalModel class&lt;/span&gt;
&lt;span class="cm"&gt; */&lt;/span&gt;

&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;ifndef&lt;/span&gt; &lt;span class="nx"&gt;CTHEORETICALMODEL_H_&lt;/span&gt;
&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;define&lt;/span&gt; &lt;span class="nx"&gt;CTHEORETICALMODEL_H_&lt;/span&gt;


&lt;span class="cm"&gt;/**&lt;/span&gt;
&lt;span class="cm"&gt; *  brief  Theoretical Model derived in section 2, on page 1&lt;/span&gt;
&lt;span class="cm"&gt; *&lt;/span&gt;
&lt;span class="cm"&gt; *  This is a detailed description of the model&lt;/span&gt;
&lt;span class="cm"&gt; */&lt;/span&gt;
&lt;span class="kr"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;CTheoreticalModel&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kr"&gt;private&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="kr"&gt;double&lt;/span&gt;    &lt;span class="nx"&gt;m_alpha&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    &lt;span class="c1"&gt;///&amp;lt; [parameter] defined in equation 2.1&lt;/span&gt;
        &lt;span class="kr"&gt;double&lt;/span&gt;    &lt;span class="nx"&gt;m_beta&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;     &lt;span class="c1"&gt;///&amp;lt; [parameter] defined in equation 2.2&lt;/span&gt;

    &lt;span class="kr"&gt;public&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="cm"&gt;/**&lt;/span&gt;
&lt;span class="cm"&gt;         *  brief      Construct a new model using the given parameters&lt;/span&gt;
&lt;span class="cm"&gt;         *  param[in]  alpha   [parameter] defined in equation 2.1&lt;/span&gt;
&lt;span class="cm"&gt;         *  param[in]  beta    [parameter] defined in equation 2.2&lt;/span&gt;
&lt;span class="cm"&gt;         */&lt;/span&gt;
        &lt;span class="nx"&gt;CTheoreticalModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kr"&gt;double&lt;/span&gt; &lt;span class="nx"&gt;alpha&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kr"&gt;double&lt;/span&gt; &lt;span class="nx"&gt;beta&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;


        &lt;span class="cm"&gt;/**&lt;/span&gt;
&lt;span class="cm"&gt;         *  brief      calculates [some property] by implementing algorithm 2.1&lt;/span&gt;
&lt;span class="cm"&gt;         *              on page 1&lt;/span&gt;
&lt;span class="cm"&gt;         *  return     [some property]&lt;/span&gt;
&lt;span class="cm"&gt;         */&lt;/span&gt;
        &lt;span class="kr"&gt;double&lt;/span&gt; &lt;span class="nx"&gt;algorithmA&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;


        &lt;span class="cm"&gt;/**&lt;/span&gt;
&lt;span class="cm"&gt;         *  brief      updates the model by [some parameter] according to the&lt;/span&gt;
&lt;span class="cm"&gt;         *              dynamics of equation 2.4&lt;/span&gt;
&lt;span class="cm"&gt;         *  param[in]  gamma   [parameter] defined in equation 2.3&lt;/span&gt;
&lt;span class="cm"&gt;         */&lt;/span&gt;
        &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nx"&gt;equationB&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kr"&gt;double&lt;/span&gt; &lt;span class="nx"&gt;gamma&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;


        &lt;span class="cm"&gt;/**&lt;/span&gt;
&lt;span class="cm"&gt;         *  brief      tests [some parameter] against the model; implements&lt;/span&gt;
&lt;span class="cm"&gt;         *              equation 2.6&lt;/span&gt;
&lt;span class="cm"&gt;         *  param[in]  theta   [some parameter] defined by equation 2.5&lt;/span&gt;
&lt;span class="cm"&gt;         */&lt;/span&gt;
        &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nx"&gt;testC&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kr"&gt;double&lt;/span&gt; &lt;span class="nx"&gt;theta&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;endif&lt;/span&gt; &lt;span class="cm"&gt;/* CTHEORETICALMODEL_H_ */&lt;/span&gt;
&lt;/pre&gt;


&lt;p&gt;Then the html documentation that doxygen will generate will look like this:&lt;/p&gt;
&lt;p&gt;Now let's say that you talk to your advisor and he suggests that maybe section
2 should come after section 3. Moreover, you add a bunch of content to section
1 so now all of the code for this model is on page five. So then you end up
with this:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://www.joshbialkowski.com/es/posts/2010/wp-content/manual/01/dummy2.png"&gt;&lt;/p&gt;
&lt;p&gt;So now you have to go back and change all of the equation numbers and page
references in your code. But wait, when we wrote our document we "&lt;code&gt;label{}&lt;/code&gt;"ed
all of our equations, algorithms, and sections. Wouldn't it be cool if we
could just reference those in the comments? Doxygen exposes latex's math mode
for us to document inline equations. It uses latex to render the equations,
and then uses dvipng to turn those into png images. Moreover, latex has the
&lt;code&gt;xr&lt;/code&gt; package, which allows us to reference labels from other documents.
Lastly, the "&lt;code&gt;ref{}&lt;/code&gt;" command is valid inside math-mode. So we have all the
tools we need, but there is one slight problem. In order to use the &lt;code&gt;xr&lt;/code&gt; latex
package, we need to include the "&lt;code&gt;externaldocument&lt;/code&gt;" command in the header of
the document.&lt;/p&gt;
&lt;h4&gt;The solution&lt;/h4&gt;
&lt;p&gt;Now here's the fun part. When Doxygen renders all of the equations, it does so
by generating a single latex source file called "&lt;code&gt;_formulas.tex&lt;/code&gt;". We don't
have explicit access to modify the preamble of that source file, but we are
allowed to add optional packages to the list of what is included. We do that
by modifying the "&lt;code&gt;EXTRA_PACKAGES&lt;/code&gt;" line of the doxyfile. For instance, if we
edit the doxyfile like this:&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;…
# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX 
# packages that should be included in the LaTeX output.

EXTRA_PACKAGES = amsmath xr amsfonts
…
&lt;/pre&gt;


&lt;p&gt;then when doxygen generates &lt;code&gt;_formulas.tex&lt;/code&gt; it will include in the preamble a
list of includes like this&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;    usepackage{amsmath}
    usepackage{xr}
    usepackage{amsfonts}
&lt;/pre&gt;


&lt;p&gt;Note that Doxygen tokenizes the list of packages (parses it) at whitespace,
and then takes each token and wraps it with "usepackage{}", inserting it into
the header. We can hijack this method of input by making &lt;code&gt;EXTRA_PACKAGES&lt;/code&gt;
variable like this&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;…
EXTRA_PACKAGES = amsmath xr}externaldocument[paper-]{dummy}% amsfonts
…
&lt;/pre&gt;


&lt;p&gt;Then the preamble of &lt;code&gt;_formulas.tex&lt;/code&gt; will look like this&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;    usepackage{amsmath}
    usepackage{amsfonts}
    usepackage{xr}externaldocument[paper-]{dummy}%}
    usepackage{hyperref}
&lt;/pre&gt;


&lt;p&gt;Note how we use a comment character (percent) to comment out the closing
bracket that doxygen put's around our 'package'. Now we have an extra command
in our preamble. If you haven't looked up the &lt;code&gt;xr&lt;/code&gt; documentation yet, this
command means to look for a file called "&lt;code&gt;dummy.aux&lt;/code&gt;" generated by latex. The
package extracts all the labels from that file and appends "&lt;code&gt;paper-&lt;/code&gt;" to the
front of the label names. Now we can change our code documentation to look
like this:&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="cm"&gt;/**&lt;/span&gt;
&lt;span class="cm"&gt; *  file       CTheoreticalModel.h&lt;/span&gt;
&lt;span class="cm"&gt; *  author     Joe Author (jauthor@institute.edu)&lt;/span&gt;
&lt;span class="cm"&gt; *  date       Apr 17, 2010&lt;/span&gt;
&lt;span class="cm"&gt; *  brief      Definition file for CTheoreticalModel class&lt;/span&gt;
&lt;span class="cm"&gt; */&lt;/span&gt;

&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;ifndef&lt;/span&gt; &lt;span class="nx"&gt;CTHEORETICALMODEL_H_&lt;/span&gt;
&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;define&lt;/span&gt; &lt;span class="nx"&gt;CTHEORETICALMODEL_H_&lt;/span&gt;


&lt;span class="cm"&gt;/**&lt;/span&gt;
&lt;span class="cm"&gt; *  brief  Theoretical Model derived in section f$ref{paper-sec:Model}f$,&lt;/span&gt;
&lt;span class="cm"&gt; *          page f$pageref{paper-sec:Model}f$&lt;/span&gt;
&lt;span class="cm"&gt; *&lt;/span&gt;
&lt;span class="cm"&gt; *  This is a detailed description of the model&lt;/span&gt;
&lt;span class="cm"&gt; */&lt;/span&gt;
&lt;span class="kr"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;CTheoreticalModel&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kr"&gt;private&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="kr"&gt;double&lt;/span&gt;    &lt;span class="nx"&gt;m_alpha&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    &lt;span class="c1"&gt;///&amp;lt; [parameter] defined in equation f$ref{paper-eqn:alphaDef}f$&lt;/span&gt;
        &lt;span class="kr"&gt;double&lt;/span&gt;    &lt;span class="nx"&gt;m_beta&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;     &lt;span class="c1"&gt;///&amp;lt; [parameter] defined in equation f$ref{paper-eqn:betaDef}f$&lt;/span&gt;

    &lt;span class="kr"&gt;public&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="cm"&gt;/**&lt;/span&gt;
&lt;span class="cm"&gt;         *  brief      Construct a new model using the given parameters&lt;/span&gt;
&lt;span class="cm"&gt;         *  param[in]  alpha   [parameter] defined in equation&lt;/span&gt;
&lt;span class="cm"&gt;         *                      f$ref{paper-eqn:alphaDef}f$&lt;/span&gt;
&lt;span class="cm"&gt;         *  param[in]  beta    [parameter] defined in equation&lt;/span&gt;
&lt;span class="cm"&gt;         *                      f$ref{paper-eqn:betaDef}f$&lt;/span&gt;
&lt;span class="cm"&gt;         */&lt;/span&gt;
        &lt;span class="nx"&gt;CTheoreticalModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kr"&gt;double&lt;/span&gt; &lt;span class="nx"&gt;alpha&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kr"&gt;double&lt;/span&gt; &lt;span class="nx"&gt;beta&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;


        &lt;span class="cm"&gt;/**&lt;/span&gt;
&lt;span class="cm"&gt;         *  brief      calculates [some property] by implementing algorithm&lt;/span&gt;
&lt;span class="cm"&gt;         *              f$ref{paper-alg:SomeAlgorithm}f$ on page&lt;/span&gt;
&lt;span class="cm"&gt;         *              f$pageref{paper-alg:SomeAlgorithm}f$&lt;/span&gt;
&lt;span class="cm"&gt;         *  return     [some property]&lt;/span&gt;
&lt;span class="cm"&gt;         */&lt;/span&gt;
        &lt;span class="kr"&gt;double&lt;/span&gt; &lt;span class="nx"&gt;algorithmA&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;


        &lt;span class="cm"&gt;/**&lt;/span&gt;
&lt;span class="cm"&gt;         *  brief      updates the model by [some parameter] according to the&lt;/span&gt;
&lt;span class="cm"&gt;         *              dynamics of equation f$ref{paper-eqn:SomeEquation}f$&lt;/span&gt;
&lt;span class="cm"&gt;         *              on page f$pageref{paper-eqn:SomeEquation}f$&lt;/span&gt;
&lt;span class="cm"&gt;         *  param[in]  gamma   [parameter] defined in equation&lt;/span&gt;
&lt;span class="cm"&gt;         *                      f$ref{paper-eqn:gammaDef}f$&lt;/span&gt;
&lt;span class="cm"&gt;         */&lt;/span&gt;
        &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nx"&gt;equationB&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kr"&gt;double&lt;/span&gt; &lt;span class="nx"&gt;gamma&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;


        &lt;span class="cm"&gt;/**&lt;/span&gt;
&lt;span class="cm"&gt;         *  brief      tests [some parameter] against the model; implements&lt;/span&gt;
&lt;span class="cm"&gt;         *              condition f$ref{paper-eqn:SomeCondition}f$&lt;/span&gt;
&lt;span class="cm"&gt;         *  param[in]  theta   [some parameter] defined by equation&lt;/span&gt;
&lt;span class="cm"&gt;         *                      f$ref{paper-eqn:thetaDef}f$&lt;/span&gt;
&lt;span class="cm"&gt;         */&lt;/span&gt;
        &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nx"&gt;testC&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kr"&gt;double&lt;/span&gt; &lt;span class="nx"&gt;theta&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;endif&lt;/span&gt; &lt;span class="cm"&gt;/* CTHEORETICALMODEL_H_ */&lt;/span&gt;
&lt;/pre&gt;


&lt;p&gt;Now all we have to do is dump &lt;code&gt;dummy.aux&lt;/code&gt; (generated when we build the paper
using latex) into the &lt;code&gt;html&lt;/code&gt; directory where doxygen is going to build
&lt;code&gt;_formulas.tex&lt;/code&gt; and then when we make the documentation it looks like this:&lt;/p&gt;
&lt;p&gt;Sure, all the references are images… which isn't particularly great, but it's
a lot better than having to go in and change the labels every time we make a
change to the referenced document. Whenever writing a code and a referenced
document are done in parallel, this could be quite a handy trick. If you want
the html document to look a little more professional, add a package that will
set the font to the same as the font set by your doxygen &lt;code&gt;CSS&lt;/code&gt; stylesheet.&lt;/p&gt;
&lt;p&gt;If you want to play around with the files used in this post, pick them up
here: &lt;a href="https://www.joshbialkowski.com/es/posts/2010/wp-content/manual/01/dummy.7z"&gt;dummy.7z&lt;/a&gt;. Create the latex document
with the following command.&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;latex dummy.tex
&lt;/pre&gt;


&lt;p&gt;Then copy &lt;code&gt;dummy.aux&lt;/code&gt; into the &lt;code&gt;html&lt;/code&gt; directory.&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;cp dummy.aux html/
&lt;/pre&gt;


&lt;p&gt;Then run doxygen&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;doxygen doxyfile
&lt;/pre&gt;&lt;/div&gt;</description><guid>https://www.joshbialkowski.com/es/posts/2010/html-documentation-with-equation-numbers-referencing-an-external-pdf-document-with-doxygens-html-documentation.html</guid><pubDate>Sat, 17 Apr 2010 20:17:44 GMT</pubDate></item></channel></rss>