Skip to main content

The LatexCodeGenerator Class Reference

Generator for LaTeX code fragments. More...

Declaration

class LatexCodeGenerator { ... }

Included Headers

#include <src/latexgen.h>

Base class

classOutputCodeIntf

Base class for code generators. More...

Public Constructors Index

LatexCodeGenerator (TextStream *t, const QCString &relPath, const QCString &sourceFile)
LatexCodeGenerator (TextStream *t)

Public Member Functions Index

voidsetTextStream (TextStream *t)
OutputTypetype () const override
std::unique_ptr< OutputCodeIntf >clone () override
voidcodify (const QCString &text) override
voidstripCodeComments (bool b) override
voidstartSpecialComment () override
voidendSpecialComment () override
voidsetStripIndentAmount (size_t amount) override
voidwriteCodeLink (CodeSymbolType type, const QCString &ref, const QCString &file, const QCString &anchor, const QCString &name, const QCString &tooltip) override
voidwriteTooltip (const QCString &, const DocLinkInfo &, const QCString &, const QCString &, const SourceLinkInfo &, const SourceLinkInfo &) override
voidwriteLineNumber (const QCString &, const QCString &, const QCString &, int, bool) override
voidstartCodeLine (int) override
voidendCodeLine () override
voidstartFontClass (const QCString &) override
voidendFontClass () override
voidwriteCodeAnchor (const QCString &) override
voidstartCodeFragment (const QCString &style) override
voidendCodeFragment (const QCString &style) override
voidstartFold (int, const QCString &, const QCString &) override
voidendFold () override
voidincUsedTableLevel ()
voiddecUsedTableLevel ()
intusedTableLevel () const
voidsetRelativePath (const QCString &path)
voidsetSourceFileName (const QCString &sourceFileName)
voidsetInsideTabbing (bool b)
boolinsideTabbing () const

Private Member Functions Index

void_writeCodeLink (const QCString &className, const QCString &ref, const QCString &file, const QCString &anchor, const QCString &name, const QCString &tooltip)
voiddocify (const QCString &str)

Private Member Attributes Index

boolm_streamSet = false
TextStream *m_t
QCStringm_relPath
QCStringm_sourceFileName
size_tm_col = 0
boolm_doxyCodeLineOpen = false
intm_usedTableLevel = 0
boolm_insideTabbing = false
boolm_stripCodeComments = false
boolm_hide = false
size_tm_stripIndentAmount = 0

Description

Generator for LaTeX code fragments.

Definition at line 27 of file latexgen.h.

Public Constructors

LatexCodeGenerator()

LatexCodeGenerator::LatexCodeGenerator (TextStream * t, const QCString & relPath, const QCString & sourceFile)

Declaration at line 30 of file latexgen.h, definition at line 59 of file latexgen.cpp.

59LatexCodeGenerator::LatexCodeGenerator(TextStream *t,const QCString &relPath,const QCString &sourceFileName)
60 : m_t(t), m_relPath(relPath), m_sourceFileName(sourceFileName)
61{
62}

References m_relPath, m_sourceFileName and m_t.

LatexCodeGenerator()

LatexCodeGenerator::LatexCodeGenerator (TextStream * t)

Declaration at line 31 of file latexgen.h, definition at line 64 of file latexgen.cpp.

Reference m_t.

Public Member Functions

clone()

std::unique_ptr< OutputCodeIntf > LatexCodeGenerator::clone ()
inline virtual

Definition at line 35 of file latexgen.h.

35 std::unique_ptr<OutputCodeIntf> clone() override { return std::make_unique<LatexCodeGenerator>(*this); }

codify()

void LatexCodeGenerator::codify (const QCString & text)
virtual

Declaration at line 36 of file latexgen.h, definition at line 78 of file latexgen.cpp.

79{
80 if (!str.isEmpty())
81 {
82 const char *p=str.data();
83 char c = 0;
84 //char cs[5];
85 int tabSize = Config_getInt(TAB_SIZE);
86 static THREAD_LOCAL char *result = nullptr;
87 static THREAD_LOCAL int lresult = 0;
88 if (m_hide) // only update column count
89 {
91 }
92 else // actually output content and keep track of m_col
93 {
94 while ((c=*p))
95 {
96 switch(c)
97 {
98 case 0x0c: p++; // remove ^L
99 break;
100 case ' ': if (m_col>=m_stripIndentAmount)
101 {
102 *m_t << (m_doxyCodeLineOpen ? "\\ " : " ");
103 }
104 m_col++;
105 p++;
106 break;
107 case '^': *m_t <<"\\string^";
108 m_col++;
109 p++;
110 break;
111 case '`': *m_t <<"\\`{}";
112 m_col++;
113 p++;
114 break;
115 case '\t': {
116 int spacesToNextTabStop = tabSize - (m_col%tabSize);
117 while (spacesToNextTabStop--)
118 {
120 {
121 *m_t << (m_doxyCodeLineOpen ? "\\ " : " ");
122 }
123 m_col++;
124 }
125 p++;
126 }
127 break;
128 case '\n': *m_t << '\n';
129 m_col=0;
130 p++;
131 break;
132 default:
133 {
134 int i=0;
135
136#undef COPYCHAR
137// helper macro to copy a single utf8 character, dealing with multibyte chars.
138#define COPYCHAR() do { \
139 int bytes = getUTF8CharNumBytes(c); \
140 if (lresult < (i + bytes + 1)) \
141 { \
142 lresult += 512; \
143 result = static_cast<char *>(realloc(result, lresult)); \
144 } \
145 for (int j=0; j<bytes && *p; j++) \
146 { \
147 result[i++]=*p++; \
148 } \
149 m_col++; \
150 } while(0)
151
152 // gather characters until we find whitespace or another special character
153 COPYCHAR();
154 while ((c=*p) &&
155 c!=0x0c && c!='\t' && c!='\n' && c!=' ' && c!='^'
156 )
157 {
158 COPYCHAR();
159 }
160 result[i]=0; // add terminator
161 filterLatexString(*m_t,result,
162 m_insideTabbing, // insideTabbing
163 true, // insidePre
164 false, // insideItem
165 m_usedTableLevel>0, // insideTable
166 false // keepSpaces
167 );
168 }
169 break;
170 }
171 }
172 }
173 }
174}

References Config_getInt, COPYCHAR, QCString::data, filterLatexString, QCString::isEmpty, m_col, m_doxyCodeLineOpen, m_hide, m_insideTabbing, m_stripIndentAmount, m_t, m_usedTableLevel, THREAD_LOCAL and updateColumnCount.

Referenced by endCodeLine, writeCodeLink and writeLineNumber.

decUsedTableLevel()

void LatexCodeGenerator::decUsedTableLevel ()
inline

Definition at line 65 of file latexgen.h.

Reference m_usedTableLevel.

endCodeFragment()

void LatexCodeGenerator::endCodeFragment (const QCString & style)
virtual

Declaration at line 59 of file latexgen.h, definition at line 308 of file latexgen.cpp.

309{
310 //endCodeLine checks is there is still an open code line, if so closes it.
312
313 *m_t << "\\end{" << style << "}\n";
314}

References endCodeLine and m_t.

endCodeLine()

void LatexCodeGenerator::endCodeLine ()
virtual

Declaration at line 54 of file latexgen.h, definition at line 280 of file latexgen.cpp.

281{
282 if (m_hide) return;
284 {
285 *m_t << "}";
287 }
288 codify("\n");
289}

References codify, FALSE, m_doxyCodeLineOpen, m_hide and m_t.

Referenced by endCodeFragment.

endFold()

void LatexCodeGenerator::endFold ()
inline virtual

Definition at line 61 of file latexgen.h.

61 void endFold() override {}

endFontClass()

void LatexCodeGenerator::endFontClass ()
virtual

Declaration at line 56 of file latexgen.h, definition at line 297 of file latexgen.cpp.

298{
299 if (m_hide) return;
300 *m_t << "}";
301}

References m_hide and m_t.

endSpecialComment()

void LatexCodeGenerator::endSpecialComment ()
virtual

Declaration at line 39 of file latexgen.h, definition at line 186 of file latexgen.cpp.

187{
188 m_hide = false;
189}

Reference m_hide.

incUsedTableLevel()

void LatexCodeGenerator::incUsedTableLevel ()
inline

Definition at line 64 of file latexgen.h.

Reference m_usedTableLevel.

insideTabbing()

bool LatexCodeGenerator::insideTabbing ()
inline

Definition at line 71 of file latexgen.h.

71 bool insideTabbing() const { return m_insideTabbing; }

Reference m_insideTabbing.

setInsideTabbing()

void LatexCodeGenerator::setInsideTabbing (bool b)
inline

Definition at line 70 of file latexgen.h.

70 void setInsideTabbing(bool b) { m_insideTabbing=b; }

Reference m_insideTabbing.

setRelativePath()

void LatexCodeGenerator::setRelativePath (const QCString & path)

Declaration at line 68 of file latexgen.h, definition at line 68 of file latexgen.cpp.

69{
70 m_relPath = path;
71}

Reference m_relPath.

setSourceFileName()

void LatexCodeGenerator::setSourceFileName (const QCString & sourceFileName)

Declaration at line 69 of file latexgen.h, definition at line 73 of file latexgen.cpp.

Reference m_sourceFileName.

setStripIndentAmount()

void LatexCodeGenerator::setStripIndentAmount (size_t amount)
virtual

Declaration at line 40 of file latexgen.h, definition at line 191 of file latexgen.cpp.

192{
193 m_stripIndentAmount = amount;
194}

Reference m_stripIndentAmount.

setTextStream()

void LatexCodeGenerator::setTextStream (TextStream * t)
inline

Definition at line 32 of file latexgen.h.

32 void setTextStream(TextStream *t) { m_t = t; }

Reference m_t.

startCodeFragment()

void LatexCodeGenerator::startCodeFragment (const QCString & style)
virtual

Declaration at line 58 of file latexgen.h, definition at line 303 of file latexgen.cpp.

304{
305 *m_t << "\n\\begin{" << style << "}{" << m_usedTableLevel << "}\n";
306}

References m_t and m_usedTableLevel.

startCodeLine()

void LatexCodeGenerator::startCodeLine (int)
virtual

Declaration at line 53 of file latexgen.h, definition at line 269 of file latexgen.cpp.

270{
271 if (m_hide) return;
272 m_col=0;
274 {
275 *m_t << "\\DoxyCodeLine{";
277 }
278}

References m_col, m_doxyCodeLineOpen, m_hide, m_t and TRUE.

startFold()

void LatexCodeGenerator::startFold (int, const QCString &, const QCString &)
inline virtual

Definition at line 60 of file latexgen.h.

60 void startFold(int,const QCString &,const QCString &) override {}

startFontClass()

void LatexCodeGenerator::startFontClass (const QCString & name)
virtual

Declaration at line 55 of file latexgen.h, definition at line 291 of file latexgen.cpp.

292{
293 if (m_hide) return;
294 *m_t << "\\textcolor{" << name << "}{";
295}

References m_hide and m_t.

startSpecialComment()

void LatexCodeGenerator::startSpecialComment ()
virtual

Declaration at line 38 of file latexgen.h, definition at line 181 of file latexgen.cpp.

References m_hide and m_stripCodeComments.

stripCodeComments()

void LatexCodeGenerator::stripCodeComments (bool b)
virtual

Declaration at line 37 of file latexgen.h, definition at line 176 of file latexgen.cpp.

Reference m_stripCodeComments.

type()

OutputType LatexCodeGenerator::type ()
inline virtual

Definition at line 34 of file latexgen.h.

34 OutputType type() const override { return OutputType::Latex; }

Reference Latex.

usedTableLevel()

int LatexCodeGenerator::usedTableLevel ()
inline

Definition at line 66 of file latexgen.h.

66 int usedTableLevel() const { return m_usedTableLevel; }

Reference m_usedTableLevel.

writeCodeAnchor()

void LatexCodeGenerator::writeCodeAnchor (const QCString &)
inline virtual

Definition at line 57 of file latexgen.h.

57 void writeCodeAnchor(const QCString &) override {}

writeCodeLink()

void LatexCodeGenerator::writeCodeLink (CodeSymbolType type, const QCString & ref, const QCString & file, const QCString & anchor, const QCString & name, const QCString & tooltip)
virtual

Declaration at line 41 of file latexgen.h, definition at line 196 of file latexgen.cpp.

197 const QCString &ref,const QCString &f,
198 const QCString &anchor,const QCString &name,
199 const QCString &)
200{
201 if (m_hide) return;
202 bool pdfHyperlinks = Config_getBool(PDF_HYPERLINKS);
203 bool usePDFLatex = Config_getBool(USE_PDFLATEX);
204 size_t l = name.length();
205 if (ref.isEmpty() && usePDFLatex && pdfHyperlinks)
206 {
207 *m_t << "\\mbox{\\hyperlink{";
208 if (!f.isEmpty()) *m_t << stripPath(f);
209 if (!f.isEmpty() && !anchor.isEmpty()) *m_t << "_";
210 if (!anchor.isEmpty()) *m_t << anchor;
211 *m_t << "}{";
212 codify(name);
213 *m_t << "}}";
214 }
215 else
216 {
217 codify(name);
218 }
219 m_col+=l;
220}

References codify, Config_getBool, QCString::isEmpty, QCString::length, m_col, m_hide, m_t and stripPath.

Referenced by writeLineNumber.

writeLineNumber()

void LatexCodeGenerator::writeLineNumber (const QCString & ref, const QCString & fileName, const QCString & anchor, int l, bool writeLineAnchor)
virtual

Declaration at line 52 of file latexgen.h, definition at line 222 of file latexgen.cpp.

222void LatexCodeGenerator::writeLineNumber(const QCString &ref,const QCString &fileName,const QCString &anchor,int l,bool writeLineAnchor)
223{
224 if (m_hide) return;
225 bool usePDFLatex = Config_getBool(USE_PDFLATEX);
226 bool pdfHyperlinks = Config_getBool(PDF_HYPERLINKS);
228 {
229 *m_t << "\\DoxyCodeLine{";
231 }
232 if (Config_getBool(SOURCE_BROWSER))
233 {
234 QCString lineNumber;
235 lineNumber.sprintf("%05d",l);
236
237 QCString lineAnchor;
238 if (!m_sourceFileName.isEmpty())
239 {
240 lineAnchor.sprintf("_l%05d",l);
242 }
243 bool showTarget = usePDFLatex && pdfHyperlinks && !lineAnchor.isEmpty() && writeLineAnchor;
244 if (showTarget)
245 {
246 *m_t << "\\Hypertarget{" << stripPath(lineAnchor) << "}";
247 }
248 if (!fileName.isEmpty())
249 {
250 writeCodeLink(CodeSymbolType::Default,ref,fileName,anchor,lineNumber,QCString());
251 }
252 else
253 {
254 codify(lineNumber);
255 }
256 *m_t << "\\ ";
257 }
258 else
259 {
260 QCString lineNumber;
261 lineNumber.sprintf("%05d",l);
262 codify(lineNumber);
263 *m_t << "\\ ";
264 }
265 m_col=0;
266}

References codify, Config_getBool, Default, QCString::isEmpty, m_col, m_doxyCodeLineOpen, m_hide, m_sourceFileName, m_t, QCString::prepend, QCString::sprintf, stripExtensionGeneral, stripPath, TRUE and writeCodeLink.

writeTooltip()

void LatexCodeGenerator::writeTooltip (const QCString &, const DocLinkInfo &, const QCString &, const QCString &, const SourceLinkInfo &, const SourceLinkInfo &)
inline virtual

Definition at line 45 of file latexgen.h.

45 void writeTooltip(const QCString &,
46 const DocLinkInfo &,
47 const QCString &,
48 const QCString &,
49 const SourceLinkInfo &,
50 const SourceLinkInfo &
51 ) override {}

Private Member Functions

_writeCodeLink()

void LatexCodeGenerator::_writeCodeLink (const QCString & className, const QCString & ref, const QCString & file, const QCString & anchor, const QCString & name, const QCString & tooltip)

Definition at line 74 of file latexgen.h.

docify()

void LatexCodeGenerator::docify (const QCString & str)

Definition at line 78 of file latexgen.h.

Private Member Attributes

m_col

size_t LatexCodeGenerator::m_col = 0

Definition at line 83 of file latexgen.h.

83 size_t m_col = 0;

Referenced by codify, startCodeLine, writeCodeLink and writeLineNumber.

m_doxyCodeLineOpen

bool LatexCodeGenerator::m_doxyCodeLineOpen = false

Definition at line 84 of file latexgen.h.

84 bool m_doxyCodeLineOpen = false;

Referenced by codify, endCodeLine, startCodeLine and writeLineNumber.

m_hide

bool LatexCodeGenerator::m_hide = false

m_insideTabbing

bool LatexCodeGenerator::m_insideTabbing = false

Definition at line 86 of file latexgen.h.

86 bool m_insideTabbing = false;

Referenced by codify, insideTabbing and setInsideTabbing.

m_relPath

QCString LatexCodeGenerator::m_relPath

Definition at line 81 of file latexgen.h.

Referenced by LatexCodeGenerator and setRelativePath.

m_sourceFileName

QCString LatexCodeGenerator::m_sourceFileName

Definition at line 82 of file latexgen.h.

Referenced by LatexCodeGenerator, setSourceFileName and writeLineNumber.

m_streamSet

bool LatexCodeGenerator::m_streamSet = false

Definition at line 79 of file latexgen.h.

79 bool m_streamSet = false;

m_stripCodeComments

bool LatexCodeGenerator::m_stripCodeComments = false

Definition at line 87 of file latexgen.h.

87 bool m_stripCodeComments = false;

Referenced by startSpecialComment and stripCodeComments.

m_stripIndentAmount

size_t LatexCodeGenerator::m_stripIndentAmount = 0

Definition at line 89 of file latexgen.h.

Referenced by codify and setStripIndentAmount.

m_t

m_usedTableLevel

int LatexCodeGenerator::m_usedTableLevel = 0

Definition at line 85 of file latexgen.h.

Referenced by codify, decUsedTableLevel, incUsedTableLevel, startCodeFragment and usedTableLevel.


The documentation for this class was generated from the following files:


Generated via doxygen2docusaurus by Doxygen 1.14.0.