fghoussen
fghoussen

Reputation: 565

How to use doxygen to produce a pdf with custom latex stylesheet and commands?

How to use doxygen to produce a pdf with custom latex stylesheet and commands ?

I need to document this code :

~\doxygenLaTex> more main.cpp
#include <iostream>
//! \page MainPage Main program
//! This program is meant to say hello!
int main() {std::cout << "Hello World!"; return 0;}

I need to get a pdf document with my custom style mystyle.sty which includes custom LaTex commands, like \mytable, I need to use inside the doc :

~\doxygenLaTex> more mystyle.sty
\NeedsTeXFormat{LaTeX2e}[1999/01/01]
\ProvidesPackage{mystyle}[2018/05/28]

\newcommand*{\mytable}{%
  \begin{tabular}{ll}
    1 & 2 \\
    3 & 4 \\
  \end{tabular}
}

\endinput

So I look for how to use doxygen for that :

~\doxygenLaTex> ls
Doxyfile main.cpp mainpage.dox mystyle.sty

~\doxygenLaTex>  more .\mainpage.dox
//!
//! \mytable
//!
//! \page MainPage
//!

~\doxygenLaTex> grep LATEX_EXTRA_STYLE .\Doxyfile
# The LATEX_EXTRA_STYLESHEET tag can be used to specify additional user-defined
LATEX_EXTRA_STYLESHEET = mystyle.sty

~\doxygenLaTex> grep ALIASES .\Doxyfile
ALIASES                = "mytable=\\mytable"

Despite reading the doc, it didn't work: I get command as text ! Running doxygen; cd latex; make pdf; AcroRd32.exe refman.pdf gives :

enter image description here

I googled this and found Doxygen: include custom latex command or How to get Doxygen to recognize custom latex command which unfortunately didn't help me.

Tried a bit more stuffs, but did not work either :

~\doxygenLaTex> git diff
diff --git a/Doxyfile b/Doxyfile
-ALIASES                = "mytable=\\mytable"
+ALIASES                = "mytable=\mytable"

~\doxygenLaTex> git diff
diff --git a/Doxyfile b/Doxyfile
-ALIASES                = "mytable=\\mytable"
+ALIASES                = "mytable=@mytable"


The problem seems to be I get this kind of things :

~\doxygenLaTex\latex> more .\_main_page.tex
This program is meant to say hello!

\textbackslash{}mytable

But not

~\doxygenLaTex\latex> more .\_main_page.tex
This program is meant to say hello!

\mytable

What did I miss ?

Additional question : is there a way to not use doxygen.sty but really only mystyle.sty to avoid any kind of conflicts ?

~\doxygenLaTex\latex> grep usepackage refman.tex
\usepackage{doxygen}
\usepackage{mystyle}

Franck

Note : Windows 10, doxygen 1.9.1

EDIT

When googling before posting, I tested \latexonly. This

~\doxygenLaTex> git diff
diff --git a/Doxyfile b/Doxyfile
-ALIASES                = "mytable=\\mytable"
+ALIASES                = "\\latexonly mytable=\\mytable \\endlatexonly"

Or this

~\doxygenLaTex> git diff
diff --git a/Doxyfile b/Doxyfile
-ALIASES                = "mytable=\\mytable"
+ALIASES                = "\latexonly mytable=\\mytable \endlatexonly"

was not working. But, indeed, it turns out this

~\doxygenLaTex> git diff
diff --git a/mainpage.dox b/mainpage.dox
-//! \mytable
+//! \latexonly \mytable \endlatexonly

does work and produce almost the result I expected:

enter image description here

But now I have another problem : the real \mytable is no table and needs to be set not here :

~\doxygenLaTex\latex> more .\_main_page.tex
This program is meant to say hello!

 \mytable

But actually here

~\doxygenLaTex\latex> more .\refman.tex
\begin{document}
 \mytable

Is there a way to locate LaTex commands here ? And ideally to not use doxygen.sty but really only mystyle.sty to avoid any kind of conflicts ?

Upvotes: 1

Views: 3312

Answers (1)

albert
albert

Reputation: 9037

When I understand it correct you want to use the LaTeX command \mytable in your LaTeX output / resulting pdf.

Most steps done are correct thought the problem is that \mytable is a LaTeX command and not a doxygen command, so you have to make it known in the doxygen parsed comment.

For this there are a few possibilities:

  • the \latexonly ... \endlatexonly i.e. in the comment add:
      \latexonly
      \mytable
      \endlatexonly
    
  • use it as a formula
    \f[ \mytable \f]
    

Of course you can pack the above snippets in a dedicated ALIASES.

So all in all I used:

Doxyfile

LATEX_EXTRA_STYLESHEET = mystyle.sty

main.cpp

#include <iostream>
/** \page MainPage Main program
 * This program is meant to say hello!
 *
 * \latexonly
 * \mytable
 * \endlatexonly
 *
 * \f[ \mytable \f]
 */
int main() {std::cout << "Hello World!"; return 0;}

mystyle.sty

\NeedsTeXFormat{LaTeX2e}[1999/01/01]
\ProvidesPackage{mystyle}[2018/05/28]

\newcommand*{\mytable}{%
  \begin{tabular}{ll}
    1 & 2 \\
    3 & 4 \\
  \end{tabular}
}

Upvotes: 1

Related Questions