My Project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions
latexgen.cpp File Reference
#include <stdlib.h>
#include <qdir.h>
#include "latexgen.h"
#include "config.h"
#include "message.h"
#include "doxygen.h"
#include "util.h"
#include "diagram.h"
#include "language.h"
#include "version.h"
#include "dot.h"
#include "pagedef.h"
#include "docparser.h"
#include "latexdocvisitor.h"
#include "dirdef.h"
#include "cite.h"
#include "groupdef.h"
#include "classlist.h"
#include "namespacedef.h"
#include "filename.h"
#include "resourcemgr.h"

Go to the source code of this file.

Macros

#define COPYCHAR()
 

Functions

static void writeLatexMakefile ()
 
static void writeMakeBat ()
 
static void writeDefaultHeaderPart1 (FTextStream &t)
 
static void writeDefaultHeaderPart2 (FTextStream &t)
 
static void writeDefaultHeaderPart3 (FTextStream &t)
 
static void writeDefaultStyleSheet (FTextStream &t)
 
static void writeDefaultFooter (FTextStream &t)
 

Macro Definition Documentation

#define COPYCHAR ( )
Value:
do { \
result[i++]=c; p++; \
if (c<0) /* multibyte utf-8 character */ \
{ \
/* 1xxx.xxxx: >=2 byte character */ \
result[i++]=*p++; \
if (((uchar)c&0xE0)==0xE0) \
{ \
/* 111x.xxxx: >=3 byte character */ \
result[i++]=*p++; \
} \
if (((uchar)c&0xF0)==0xF0) \
{ \
/* 1111.xxxx: 4 byte character */ \
result[i++]=*p++; \
} \
} \
m_col++; \
} while(0)

Referenced by LatexCodeGenerator::codify().

Function Documentation

static void writeDefaultFooter ( FTextStream t)
static

Definition at line 728 of file latexgen.cpp.

References Doxygen::citeDict, Config_getBool, theTranslator, Translator::trRTFGeneralIndex(), and CiteDict::writeLatexBibliography().

Referenced by LatexGenerator::endIndexSection(), and LatexGenerator::writeFooterFile().

{
t << "%--- End generated contents ---\n"
"\n";
// Bibliography
// Index
t << "% Index\n";
QCString unit;
if (Config_getBool(COMPACT_LATEX))
{
unit = "section";
}
else
{
unit = "chapter";
t << "\\backmatter\n";
}
t << "\\newpage\n"
"\\phantomsection\n"
"\\clearemptydoublepage\n"
"\\addcontentsline{toc}{" << unit << "}{" << theTranslator->trRTFGeneralIndex() << "}\n"
"\\printindex\n"
"\n"
"\\end{document}\n";
}
static void writeDefaultHeaderPart1 ( FTextStream t)
static

Definition at line 454 of file latexgen.cpp.

References checkExtension(), Config_getBool, Config_getEnum, Config_getList, Config_getString, dateToString(), filterLatexString(), Translator::idLanguage(), Translator::latexLanguageSupportCommand(), latexStyleExtension, stripExtensionGeneral(), theTranslator, Translator::trGeneratedAt(), Translator::trGeneratedBy(), and writeExtraLatexPackages().

Referenced by LatexGenerator::startIndexSection(), and LatexGenerator::writeHeaderFile().

{
// part 1
// Handle batch mode
if (Config_getBool(LATEX_BATCHMODE))
t << "\\batchmode\n";
// Set document class depending on configuration
QCString documentClass;
if (Config_getBool(COMPACT_LATEX))
documentClass = "article";
else
documentClass = "book";
t << "\\documentclass[twoside]{" << documentClass << "}\n"
"\n";
// Load required packages
t << "% Packages required by doxygen\n"
"\\usepackage{fixltx2e}\n" // for \textsubscript
"\\usepackage{calc}\n"
"\\usepackage{doxygen}\n"
"\\usepackage[export]{adjustbox} % also loads graphicx\n";
QStrList extraLatexStyle = Config_getList(LATEX_EXTRA_STYLESHEET);
for (uint i=0; i<extraLatexStyle.count(); ++i)
{
QCString fileName(extraLatexStyle.at(i));
if (!fileName.isEmpty())
{
QFileInfo fi(fileName);
if (fi.exists())
{
if (checkExtension(fi.fileName().data(), latexStyleExtension))
{
// strip the extension, it will be added by the usepackage in the tex conversion process
t << "\\usepackage{" << stripExtensionGeneral(fi.fileName().data(), latexStyleExtension) << "}\n";
}
else
{
t << "\\usepackage{" << fi.fileName().utf8() << "}\n";
}
}
}
}
t << "\\usepackage{graphicx}\n"
"\\usepackage[utf8]{inputenc}\n"
"\\usepackage{makeidx}\n"
"\\usepackage{multicol}\n"
"\\usepackage{multirow}\n"
"\\PassOptionsToPackage{warn}{textcomp}\n"
"\\usepackage{textcomp}\n"
"\\usepackage[nointegrals]{wasysym}\n"
"\\usepackage[table]{xcolor}\n"
"\n";
// Language support
QCString languageSupport = theTranslator->latexLanguageSupportCommand();
if (!languageSupport.isEmpty())
{
t << "% NLS support packages\n"
<< languageSupport
<< "\n";
}
// Define default fonts
t << "% Font selection\n"
"\\usepackage[T1]{fontenc}\n"
"\\usepackage[scaled=.90]{helvet}\n"
"\\usepackage{courier}\n"
"\\usepackage{amssymb}\n"
"\\usepackage{sectsty}\n"
"\\renewcommand{\\familydefault}{\\sfdefault}\n"
"\\allsectionsfont{%\n"
" \\fontseries{bc}\\selectfont%\n"
" \\color{darkgray}%\n"
"}\n"
"\\renewcommand{\\DoxyLabelFont}{%\n"
" \\fontseries{bc}\\selectfont%\n"
" \\color{darkgray}%\n"
"}\n"
"\\newcommand{\\+}{\\discretionary{\\mbox{\\scriptsize$\\hookleftarrow$}}{}{}}\n"
"\n";
// Define page & text layout
QCString paperName=Config_getEnum(PAPER_TYPE);
// "a4wide" package is obsolete (see bug 563698)
t << "% Page & text layout\n"
"\\usepackage{geometry}\n"
"\\geometry{%\n"
" " << paperName << "paper,%\n"
" top=2.5cm,%\n"
" bottom=2.5cm,%\n"
" left=2.5cm,%\n"
" right=2.5cm%\n"
"}\n";
// \sloppy is obsolete (see bug 563698)
// Allow a bit of overflow to go unnoticed by other means
t << "\\tolerance=750\n"
"\\hfuzz=15pt\n"
"\\hbadness=750\n"
"\\setlength{\\emergencystretch}{15pt}\n"
"\\setlength{\\parindent}{0cm}\n"
"\\setlength{\\parskip}{3ex plus 2ex minus 2ex}\n";
// Redefine paragraph/subparagraph environments, using sectsty fonts
t << "\\makeatletter\n"
"\\renewcommand{\\paragraph}{%\n"
" \\@startsection{paragraph}{4}{0ex}{-1.0ex}{1.0ex}{%\n"
" \\normalfont\\normalsize\\bfseries\\SS@parafont%\n"
" }%\n"
"}\n"
"\\renewcommand{\\subparagraph}{%\n"
" \\@startsection{subparagraph}{5}{0ex}{-1.0ex}{1.0ex}{%\n"
" \\normalfont\\normalsize\\bfseries\\SS@subparafont%\n"
" }%\n"
"}\n"
"\\makeatother\n"
"\n";
// Headers & footers
QGString genString;
QCString generatedBy;
static bool timeStamp = Config_getBool(LATEX_TIMESTAMP);
FTextStream tg(&genString);
if (timeStamp)
{
generatedBy = theTranslator->trGeneratedAt(dateToString(TRUE), Config_getString(PROJECT_NAME));
}
else
{
generatedBy = theTranslator->trGeneratedBy();
}
filterLatexString(tg, generatedBy, FALSE,FALSE,FALSE);
t << "% Headers & footers\n"
"\\usepackage{fancyhdr}\n"
"\\pagestyle{fancyplain}\n"
"\\fancyhead[LE]{\\fancyplain{}{\\bfseries\\thepage}}\n"
"\\fancyhead[CE]{\\fancyplain{}{}}\n"
"\\fancyhead[RE]{\\fancyplain{}{\\bfseries\\leftmark}}\n"
"\\fancyhead[LO]{\\fancyplain{}{\\bfseries\\rightmark}}\n"
"\\fancyhead[CO]{\\fancyplain{}{}}\n"
"\\fancyhead[RO]{\\fancyplain{}{\\bfseries\\thepage}}\n"
"\\fancyfoot[LE]{\\fancyplain{}{}}\n"
"\\fancyfoot[CE]{\\fancyplain{}{}}\n"
"\\fancyfoot[RE]{\\fancyplain{}{\\bfseries\\scriptsize " << genString << " Doxygen }}\n"
"\\fancyfoot[LO]{\\fancyplain{}{\\bfseries\\scriptsize " << genString << " Doxygen }}\n"
"\\fancyfoot[CO]{\\fancyplain{}{}}\n"
"\\fancyfoot[RO]{\\fancyplain{}{}}\n"
"\\renewcommand{\\footrulewidth}{0.4pt}\n";
if (!Config_getBool(COMPACT_LATEX))
{
t << "\\renewcommand{\\chaptermark}[1]{%\n"
" \\markboth{#1}{}%\n"
"}\n";
}
t << "\\renewcommand{\\sectionmark}[1]{%\n"
" \\markright{\\thesection\\ #1}%\n"
"}\n"
"\n";
// ToC, LoF, LoT, bibliography, and index
t << "% Indices & bibliography\n"
"\\usepackage{natbib}\n"
"\\usepackage[titles]{tocloft}\n"
"\\setcounter{tocdepth}{3}\n"
"\\setcounter{secnumdepth}{5}\n"
"\\makeindex\n"
"\n";
// Hyperlinks
bool pdfHyperlinks = Config_getBool(PDF_HYPERLINKS);
if (pdfHyperlinks)
{
t << "% Hyperlinks (required, but should be loaded last)\n"
"\\usepackage{ifpdf}\n"
"\\ifpdf\n"
" \\usepackage[pdftex,pagebackref=true]{hyperref}\n"
"\\else\n"
" \\usepackage[ps2pdf,pagebackref=true]{hyperref}\n"
"\\fi\n"
"\\hypersetup{%\n"
" colorlinks=true,%\n"
" linkcolor=blue,%\n"
" citecolor=blue,%\n"
" unicode%\n"
"}\n"
"\n";
}
// Custom commands used by the header
t << "% Custom commands\n"
"\\newcommand{\\clearemptydoublepage}{%\n"
" \\newpage{\\pagestyle{empty}\\cleardoublepage}%\n"
"}\n"
"\n";
// caption style definition
t << "\\usepackage{caption}\n"
<< "\\captionsetup{labelsep=space,justification=centering,font={bf},singlelinecheck=off,skip=4pt,position=top}\n\n";
// End of preamble, now comes the document contents
t << "%===== C O N T E N T S =====\n"
"\n"
"\\begin{document}\n";
if (theTranslator->idLanguage()=="greek")
t << "\\selectlanguage{greek}\n";
t << "\n";
// Front matter
t << "% Titlepage & ToC\n";
bool usePDFLatex = Config_getBool(USE_PDFLATEX);
if (pdfHyperlinks && usePDFLatex)
{
// To avoid duplicate page anchors due to reuse of same numbers for
// the index (be it as roman numbers)
t << "\\hypersetup{pageanchor=false,\n"
// << " bookmarks=true,\n" // commented out to prevent warning
<< " bookmarksnumbered=true,\n"
<< " pdfencoding=unicode\n"
<< " }\n";
}
t << "\\pagenumbering{alph}\n"
"\\begin{titlepage}\n"
"\\vspace*{7cm}\n"
"\\begin{center}%\n"
"{\\Large ";
}
static void writeDefaultHeaderPart2 ( FTextStream t)
static

Definition at line 683 of file latexgen.cpp.

Referenced by LatexGenerator::startIndexSection(), and LatexGenerator::writeHeaderFile().

{
// part 2
// Finalize project name
t << "}\\\\\n"
"\\vspace*{1cm}\n"
"{\\large ";
}
static void writeDefaultHeaderPart3 ( FTextStream t)
static

Definition at line 692 of file latexgen.cpp.

References Config_getBool, dateToString(), and versionString.

Referenced by LatexGenerator::endIndexSection(), and LatexGenerator::writeHeaderFile().

{
// part 3
// Finalize project number
t << " Doxygen " << versionString << "}\\\\\n";
if (Config_getBool(LATEX_TIMESTAMP))
t << "\\vspace*{0.5cm}\n"
"{\\small " << dateToString(TRUE) << "}\\\\\n";
t << "\\end{center}\n"
"\\end{titlepage}\n";
bool compactLatex = Config_getBool(COMPACT_LATEX);
if (!compactLatex)
t << "\\clearemptydoublepage\n";
t << "\\pagenumbering{roman}\n";
// ToC
t << "\\tableofcontents\n";
if (!compactLatex)
t << "\\clearemptydoublepage\n";
t << "\\pagenumbering{arabic}\n";
bool pdfHyperlinks = Config_getBool(PDF_HYPERLINKS);
bool usePDFLatex = Config_getBool(USE_PDFLATEX);
if (pdfHyperlinks && usePDFLatex)
{
// re-enable anchors again
t << "\\hypersetup{pageanchor=true}\n";
}
t << "\n"
"%--- Begin generated contents ---\n";
}
static void writeDefaultStyleSheet ( FTextStream t)
static
static void writeLatexMakefile ( )
static

Definition at line 262 of file latexgen.cpp.

References Doxygen::citeDict, Config_getBool, Config_getString, endl(), err(), and CiteDict::isEmpty().

Referenced by LatexGenerator::init().

{
bool generateBib = !Doxygen::citeDict->isEmpty();
QCString dir=Config_getString(LATEX_OUTPUT);
QCString fileName=dir+"/Makefile";
QFile file(fileName);
if (!file.open(IO_WriteOnly))
{
err("Could not open file %s for writing\n",fileName.data());
exit(1);
}
// inserted by KONNO Akihisa <konno@researchers.jp> 2002-03-05
QCString latex_command = Config_getString(LATEX_CMD_NAME);
QCString mkidx_command = Config_getString(MAKEINDEX_CMD_NAME);
// end insertion by KONNO Akihisa <konno@researchers.jp> 2002-03-05
FTextStream t(&file);
if (!Config_getBool(USE_PDFLATEX)) // use plain old latex
{
t << "all: refman.dvi" << endl
<< endl
<< "ps: refman.ps" << endl
<< endl
<< "pdf: refman.pdf" << endl
<< endl
<< "ps_2on1: refman_2on1.ps" << endl
<< endl
<< "pdf_2on1: refman_2on1.pdf" << endl
<< endl
<< "refman.ps: refman.dvi" << endl
<< "\tdvips -o refman.ps refman.dvi" << endl
<< endl;
t << "refman.pdf: refman.ps" << endl;
t << "\tps2pdf refman.ps refman.pdf" << endl << endl;
t << "refman.dvi: clean refman.tex doxygen.sty" << endl
<< "\techo \"Running latex...\"" << endl
<< "\t" << latex_command << " refman.tex" << endl
<< "\techo \"Running makeindex...\"" << endl
<< "\t" << mkidx_command << " refman.idx" << endl;
if (generateBib)
{
t << "\techo \"Running bibtex...\"" << endl;
t << "\tbibtex refman" << endl;
t << "\techo \"Rerunning latex....\"" << endl;
t << "\t" << latex_command << " refman.tex" << endl;
}
t << "\techo \"Rerunning latex....\"" << endl
<< "\t" << latex_command << " refman.tex" << endl
<< "\tlatex_count=8 ; \\" << endl
<< "\twhile egrep -s 'Rerun (LaTeX|to get cross-references right)' refman.log && [ $$latex_count -gt 0 ] ;\\" << endl
<< "\t do \\" << endl
<< "\t echo \"Rerunning latex....\" ;\\" << endl
<< "\t " << latex_command << " refman.tex ;\\" << endl
<< "\t latex_count=`expr $$latex_count - 1` ;\\" << endl
<< "\t done" << endl
<< "\t" << mkidx_command << " refman.idx" << endl
<< "\t" << latex_command << " refman.tex" << endl << endl
<< "refman_2on1.ps: refman.ps" << endl
<< "\tpsnup -2 refman.ps >refman_2on1.ps" << endl
<< endl
<< "refman_2on1.pdf: refman_2on1.ps" << endl
<< "\tps2pdf refman_2on1.ps refman_2on1.pdf" << endl;
}
else // use pdflatex for higher quality output
{
t << "all: refman.pdf" << endl << endl
<< "pdf: refman.pdf" << endl << endl;
t << "refman.pdf: clean refman.tex" << endl;
t << "\tpdflatex refman" << endl;
t << "\t" << mkidx_command << " refman.idx" << endl;
if (generateBib)
{
t << "\tbibtex refman" << endl;
t << "\tpdflatex refman" << endl;
}
t << "\tpdflatex refman" << endl
<< "\tlatex_count=8 ; \\" << endl
<< "\twhile egrep -s 'Rerun (LaTeX|to get cross-references right)' refman.log && [ $$latex_count -gt 0 ] ;\\" << endl
<< "\t do \\" << endl
<< "\t echo \"Rerunning latex....\" ;\\" << endl
<< "\t pdflatex refman ;\\" << endl
<< "\t latex_count=`expr $$latex_count - 1` ;\\" << endl
<< "\t done" << endl
<< "\t" << mkidx_command << " refman.idx" << endl
<< "\tpdflatex refman" << endl << endl;
}
t << endl
<< "clean:" << endl
<< "\trm -f "
<< "*.ps *.dvi *.aux *.toc *.idx *.ind *.ilg *.log *.out *.brf *.blg *.bbl refman.pdf" << endl;
}
static void writeMakeBat ( )
static

Definition at line 354 of file latexgen.cpp.

References Doxygen::citeDict, Config_getBool, Config_getString, endl(), err(), and CiteDict::isEmpty().

Referenced by LatexGenerator::init().

{
#if defined(_MSC_VER)
QCString dir=Config_getString(LATEX_OUTPUT);
QCString fileName=dir+"/make.bat";
QCString latex_command = Config_getString(LATEX_CMD_NAME);
QCString mkidx_command = Config_getString(MAKEINDEX_CMD_NAME);
QFile file(fileName);
bool generateBib = !Doxygen::citeDict->isEmpty();
if (!file.open(IO_WriteOnly))
{
err("Could not open file %s for writing\n",fileName.data());
exit(1);
}
FTextStream t(&file);
t << "set Dir_Old=%cd%\n";
t << "cd /D %~dp0\n\n";
t << "del /s /f *.ps *.dvi *.aux *.toc *.idx *.ind *.ilg *.log *.out *.brf *.blg *.bbl refman.pdf\n\n";
if (!Config_getBool(USE_PDFLATEX)) // use plain old latex
{
t << latex_command << " refman.tex\n";
t << "echo ----\n";
t << mkidx_command << " refman.idx\n";
if (generateBib)
{
t << "bibtex refman\n";
t << "echo ----\n";
t << latex_command << " refman.tex\n";
}
t << "setlocal enabledelayedexpansion\n";
t << "set count=8\n";
t << ":repeat\n";
t << "set content=X\n";
t << "for /F \"tokens=*\" %%T in ( 'findstr /C:\"Rerun LaTeX\" refman.log' ) do set content=\"%%~T\"\n";
t << "if !content! == X for /F \"tokens=*\" %%T in ( 'findstr /C:\"Rerun to get cross-references right\" refman.log' ) do set content=\"%%~T\"\n";
t << "if !content! == X goto :skip\n";
t << "set /a count-=1\n";
t << "if !count! EQU 0 goto :skip\n\n";
t << "echo ----\n";
t << latex_command << " refman.tex\n";
t << "goto :repeat\n";
t << ":skip\n";
t << "endlocal\n";
t << mkidx_command << " refman.idx\n";
t << latex_command << " refman.tex\n";
t << "dvips -o refman.ps refman.dvi\n";
t << "gswin32c -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite "
"-sOutputFile=refman.pdf -c save pop -f refman.ps\n";
}
else // use pdflatex
{
t << "pdflatex refman\n";
t << "echo ----\n";
t << mkidx_command << " refman.idx\n";
if (generateBib)
{
t << "bibtex refman" << endl;
t << "pdflatex refman" << endl;
}
t << "echo ----\n";
t << "pdflatex refman\n\n";
t << "setlocal enabledelayedexpansion\n";
t << "set count=8\n";
t << ":repeat\n";
t << "set content=X\n";
t << "for /F \"tokens=*\" %%T in ( 'findstr /C:\"Rerun LaTeX\" refman.log' ) do set content=\"%%~T\"\n";
t << "if !content! == X for /F \"tokens=*\" %%T in ( 'findstr /C:\"Rerun to get cross-references right\" refman.log' ) do set content=\"%%~T\"\n";
t << "if !content! == X goto :skip\n";
t << "set /a count-=1\n";
t << "if !count! EQU 0 goto :skip\n\n";
t << "echo ----\n";
t << "pdflatex refman\n";
t << "goto :repeat\n";
t << ":skip\n";
t << "endlocal\n";
t << mkidx_command << " refman.idx\n";
t << "pdflatex refman\n";
t << "cd /D %Dir_Old%\n";
t << "set Dir_Old=\n";
}
#endif
}