Doxygen
Loading...
Searching...
No Matches
latexgen.h File Reference
#include "config.h"
#include "outputgen.h"
Include dependency graph for latexgen.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  LatexCodeGenerator
 Generator for LaTeX code fragments. More...
class  LatexGenerator
 Generator for LaTeX output. More...

Macros

#define LATEX_STYLE_EXTENSION   ".sty"

Functions

void writeExtraLatexPackages (TextStream &t)
void writeLatexSpecialFormulaChars (TextStream &t)
QCString convertToLaTeX (const QCString &s, bool insideTabbing, bool keepSpaces=FALSE)
void filterLatexString (TextStream &t, const QCString &str, bool insideTabbing, bool insidePre, bool insideItem, bool insideTable, bool keepSpaces, const bool retainNewline=false)
QCString latexEscapeLabelName (const QCString &s)
QCString latexEscapeIndexChars (const QCString &s)
QCString latexEscapePDFString (const QCString &s)
QCString latexFilterURL (const QCString &s)
void latexWriteIndexItem (TextStream &t, const QCString &r1, const QCString &s2="")

Macro Definition Documentation

◆ LATEX_STYLE_EXTENSION

#define LATEX_STYLE_EXTENSION   ".sty"

Definition at line 22 of file latexgen.h.

Referenced by copyLatexStyleSheet(), and extraLatexStyleSheet().

Function Documentation

◆ convertToLaTeX()

QCString convertToLaTeX ( const QCString & s,
bool insideTabbing,
bool keepSpaces = FALSE )

Definition at line 2496 of file latexgen.cpp.

2497{
2498 TextStream t;
2499 filterLatexString(t,s,insideTabbing,false,false,false,keepSpaces);
2500 return t.str();
2501}
Text streaming class that buffers data.
Definition textstream.h:36
std::string str() const
Return the contents of the buffer as a std::string object.
Definition textstream.h:216
void filterLatexString(TextStream &t, const QCString &str, bool insideTabbing, bool insidePre, bool insideItem, bool insideTable, bool keepSpaces, const bool retainNewline)

References filterLatexString(), and TextStream::str().

Referenced by LatexGenerator::endIndexSection(), objectLinkToString(), LatexGenerator::startIndexSection(), substituteLatexKeywords(), and LatexGenerator::writeInheritedSectionTitle().

◆ filterLatexString()

void filterLatexString ( TextStream & t,
const QCString & str,
bool insideTabbing,
bool insidePre,
bool insideItem,
bool insideTable,
bool keepSpaces,
const bool retainNewline = false )

Definition at line 2353 of file latexgen.cpp.

2355{
2356 if (str.isEmpty()) return;
2357 bool pdfHyperlinks = Config_getBool(PDF_HYPERLINKS);
2358 //printf("filterLatexString(%s) insideTabbing=%d\n",qPrint(str),insideTabbing);
2359 const char *p = str.data();
2360 unsigned char pc='\0';
2361
2362 while (*p)
2363 {
2364 unsigned char c=static_cast<unsigned char>(*p++);
2365
2366 if (insidePre)
2367 {
2368 switch(c)
2369 {
2370 case 0xef: // handle U+FFFD i.e. "Replacement character" caused by octal: 357 277 275 / hexadecimal 0xef 0xbf 0xbd
2371 // the LaTeX command \ucr has been defined in doxygen.sty
2372 if (static_cast<unsigned char>(*(p)) == 0xbf && static_cast<unsigned char>(*(p+1)) == 0xbd)
2373 {
2374 t << "{\\ucr}";
2375 p += 2;
2376 }
2377 else
2378 t << static_cast<char>(c);
2379 break;
2380 case '\\': t << "\\(\\backslash\\)"; break;
2381 case '{': t << "\\{"; break;
2382 case '}': t << "\\}"; break;
2383 case '_': t << "\\_"; break;
2384 case '&': t << "\\&"; break;
2385 case '%': t << "\\%"; break;
2386 case '#': t << "\\#"; break;
2387 case '$': t << "\\$"; break;
2388 case '"': t << "\"{}"; break;
2389 case '-': t << "-\\/"; break;
2390 case '^': insideTable ? t << "\\string^" : t << static_cast<char>(c); break;
2391 case '~': t << "\\string~"; break;
2392 case '\n': if (retainNewline) t << "\\newline"; else t << ' ';
2393 break;
2394 case ' ': if (keepSpaces) t << "~"; else t << ' ';
2395 break;
2396 default:
2397 if (c<32) t << ' '; // non printable control character
2398 else t << static_cast<char>(c);
2399 break;
2400 }
2401 }
2402 else
2403 {
2404 switch(c)
2405 {
2406 case 0xef: // handle U+FFFD i.e. "Replacement character" caused by octal: 357 277 275 / hexadecimal 0xef 0xbf 0xbd
2407 // the LaTeX command \ucr has been defined in doxygen.sty
2408 if (static_cast<unsigned char>(*(p)) == 0xbf && static_cast<unsigned char>(*(p+1)) == 0xbd)
2409 {
2410 t << "{\\ucr}";
2411 p += 2;
2412 }
2413 else
2414 t << static_cast<char>(c);
2415 break;
2416 case '#': t << "\\+\\#"; break;
2417 case '$': t << "\\$"; break;
2418 case '%': t << "\\%"; break;
2419 case '^': processEntity(t,pdfHyperlinks,"$^\\wedge$","\\string^"); break;
2420 case '&': {
2421 // possibility to have a special symbol
2422 p = writeHtmlEntity(t, p-1, [](HtmlEntityMapper::SymType symType) { return HtmlEntityMapper::instance().latex(symType); }, "\\&");
2423 }
2424 break;
2425 case '*': processEntity(t,pdfHyperlinks,"$\\ast$","*"); break;
2426 case '_': if (!insideTabbing && *p) t << "\\+";
2427 t << "\\_";
2428 if (!insideTabbing && *p) t << "\\+";
2429 break;
2430 case '{': t << "\\{"; break;
2431 case '}': t << "\\}"; break;
2432 case '<': t << "$<$"; break;
2433 case '>': t << "$>$"; break;
2434 case '|': processEntity(t,pdfHyperlinks,"$\\vert$","|"); break;
2435 case '~': processEntity(t,pdfHyperlinks,"$\\sim$","\\string~"); break;
2436 case '[': if (Config_getBool(PDF_HYPERLINKS) || insideItem)
2437 t << "\\+[";
2438 else
2439 t << "[";
2440 break;
2441 case ']': if (pc=='[') t << "$\\,$";
2442 if ((Config_getBool(PDF_HYPERLINKS) || insideItem) && *p)
2443 t << "]\\+";
2444 else
2445 t << "]";
2446 break;
2447 case '-': t << "-\\/";
2448 break;
2449 case '\\': t << "\\textbackslash{}";
2450 break;
2451 case '"': t << "\"{}";
2452 break;
2453 case '`': t << "\\`{}";
2454 break;
2455 case '\'': t << "\\textquotesingle{}";
2456 break;
2457 case '\n': if (retainNewline)
2458 {
2459 t << "\\newline";
2460 if (insideTable) t << " ";
2461 }
2462 else
2463 {
2464 t << ' ';
2465 }
2466 break;
2467 case ' ': if (keepSpaces) { if (insideTabbing) t << "\\>"; else t << '~'; } else t << ' ';
2468 break;
2469
2470 default:
2471 //if (!insideTabbing && forceBreaks && c!=' ' && *p!=' ')
2472 if (!insideTabbing &&
2473 ((c>='A' && c<='Z' && pc!=' ' && !(pc>='A' && pc <= 'Z') && pc!='\0' && *p) || (pc=='.' && isId(c)))
2474 )
2475 {
2476 t << "\\+";
2477 }
2478 if (c<32)
2479 {
2480 t << ' '; // non-printable control character
2481 }
2482 else
2483 {
2484 t << static_cast<char>(c);
2485 }
2486 if (!insideTabbing && *p && ((c==':' && *p!=':') || c=='/'))
2487 {
2488 t << "\\+";
2489 }
2490 }
2491 }
2492 pc = c;
2493 }
2494}
const char * latex(SymType symb) const
Access routine to the LaTeX code of the HTML entity.
static HtmlEntityMapper & instance()
Returns the one and only instance of the HTML entity mapper.
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:167
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition qcstring.h:176
#define Config_getBool(name)
Definition config.h:33
bool insideTable(const DocNodeVariant *n)
static void processEntity(TextStream &t, bool pdfHyperlinks, const char *strForm, const char *strRepl)
const char * writeHtmlEntity(T &result, const char *s, HtmlEntityMapperFunc &&mapper, const char *fallback)
Definition util.cpp:7052
bool isId(int c)
Definition util.h:257

References Config_getBool, QCString::data(), insideTable(), HtmlEntityMapper::instance(), QCString::isEmpty(), isId(), HtmlEntityMapper::latex(), processEntity(), and writeHtmlEntity().

Referenced by LatexCodeGenerator::codify(), convertToLaTeX(), LatexGenerator::docify(), LatexDocVisitor::filter(), latexEscapeIndexChars(), latexEscapeLabelName(), and substituteLatexKeywords().

◆ latexEscapeIndexChars()

QCString latexEscapeIndexChars ( const QCString & s)

Definition at line 2548 of file latexgen.cpp.

2549{
2550 //printf("latexEscapeIndexChars(%s)\n",qPrint(s));
2551 if (s.isEmpty()) return s;
2553 TextStream t;
2554 const char *p=s.data();
2555 char c = 0;
2556 while ((c=*p++))
2557 {
2558 switch (c)
2559 {
2560 case '!': t << "\"!"; break;
2561 case '"': t << "\"\""; break;
2562 case '@': t << "\"@"; break;
2563 case '|': t << "\\texttt{\"|}"; break;
2564 case '[': t << "["; break;
2565 case ']': t << "]"; break;
2566 case '{': t << "\\lcurly{}"; break;
2567 case '}': t << "\\rcurly{}"; break;
2568 // NOTE: adding a case here, means adding it to while below as well!
2569 default:
2570 {
2571 int i=0;
2572 // collect as long string as possible, before handing it to docify
2573 tmp[i++]=c;
2574 while ((c=*p) && c!='"' && c!='@' && c!='[' && c!=']' && c!='!' && c!='{' && c!='}' && c!='|')
2575 {
2576 tmp[i++]=c;
2577 p++;
2578 }
2579 tmp[i]=0;
2580 filterLatexString(t,tmp,
2581 true, // insideTabbing
2582 false, // insidePre
2583 false, // insideItem
2584 false, // insideTable
2585 false // keepSpaces
2586 );
2587 }
2588 break;
2589 }
2590 }
2591 return t.str();
2592}
This is an alternative implementation of QCString.
Definition qcstring.h:103
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:170
@ ExplicitSize
Definition qcstring.h:150

References QCString::data(), QCString::ExplicitSize, filterLatexString(), QCString::isEmpty(), QCString::length(), and TextStream::str().

Referenced by latexWriteIndexItem(), and LatexGenerator::startMemberDoc().

◆ latexEscapeLabelName()

QCString latexEscapeLabelName ( const QCString & s)

Definition at line 2503 of file latexgen.cpp.

2504{
2505 //printf("latexEscapeLabelName(%s)\n",qPrint(s));
2506 if (s.isEmpty()) return s;
2508 TextStream t;
2509 const char *p=s.data();
2510 char c = 0;
2511 while ((c=*p++))
2512 {
2513 switch (c)
2514 {
2515 case '|': t << "\\texttt{\"|}"; break;
2516 case '!': t << "\"!"; break;
2517 case '@': t << "\"@"; break;
2518 case '%': t << "\\%"; break;
2519 case '{': t << "\\lcurly{}"; break;
2520 case '}': t << "\\rcurly{}"; break;
2521 case '~': t << "````~"; break; // to get it a bit better in index together with other special characters
2522 // NOTE: adding a case here, means adding it to while below as well!
2523 default:
2524 {
2525 int i=0;
2526 // collect as long string as possible, before handing it to docify
2527 tmp[i++]=c;
2528 while ((c=*p) && c!='@' && c!='[' && c!=']' && c!='!' && c!='{' && c!='}' && c!='|')
2529 {
2530 tmp[i++]=c;
2531 p++;
2532 }
2533 tmp[i]=0;
2534 filterLatexString(t,tmp,
2535 true, // insideTabbing
2536 false, // insidePre
2537 false, // insideItem
2538 false, // insideTable
2539 false // keepSpaces
2540 );
2541 }
2542 break;
2543 }
2544 }
2545 return t.str();
2546}

References QCString::data(), QCString::ExplicitSize, filterLatexString(), QCString::isEmpty(), QCString::length(), and TextStream::str().

Referenced by latexWriteIndexItem().

◆ latexEscapePDFString()

QCString latexEscapePDFString ( const QCString & s)

Definition at line 2594 of file latexgen.cpp.

2595{
2596 if (s.isEmpty()) return s;
2597 TextStream t;
2598 const char *p=s.data();
2599 char c = 0;
2600 while ((c=*p++))
2601 {
2602 switch (c)
2603 {
2604 case '\\': t << "\\textbackslash{}"; break;
2605 case '{': t << "\\{"; break;
2606 case '}': t << "\\}"; break;
2607 case '_': t << "\\_"; break;
2608 case '%': t << "\\%"; break;
2609 case '&': t << "\\&"; break;
2610 case '#': t << "\\#"; break;
2611 case '$': t << "\\$"; break;
2612 case '^': t << "\\string^"; break;
2613 case '~': t << "\\string~"; break;
2614 default:
2615 t << c;
2616 break;
2617 }
2618 }
2619 return t.str();
2620}

References QCString::data(), QCString::isEmpty(), and TextStream::str().

Referenced by LatexGenerator::startMemberDoc().

◆ latexFilterURL()

QCString latexFilterURL ( const QCString & s)

Definition at line 2622 of file latexgen.cpp.

2623{
2624 constexpr auto hex = "0123456789ABCDEF";
2625 if (s.isEmpty()) return s;
2626 TextStream t;
2627 const char *p=s.data();
2628 char c = 0;
2629 while ((c=*p++))
2630 {
2631 switch (c)
2632 {
2633 case '#': t << "\\#"; break;
2634 case '%': t << "\\%"; break;
2635 case '\\': t << "\\\\"; break;
2636 case '\n': break; // ignore
2637 default:
2638 if (c<0)
2639 {
2640 unsigned char id = static_cast<unsigned char>(c);
2641 t << "\\%" << hex[id>>4] << hex[id&0xF];
2642 }
2643 else
2644 {
2645 t << c;
2646 }
2647 break;
2648 }
2649 }
2650 return t.str();
2651}
static constexpr auto hex

References QCString::data(), hex, QCString::isEmpty(), and TextStream::str().

Referenced by LatexDocVisitor::operator()(), and LatexDocVisitor::operator()().

◆ latexWriteIndexItem()

void latexWriteIndexItem ( TextStream & t,
const QCString & r1,
const QCString & s2 = "" )

Definition at line 2653 of file latexgen.cpp.

2654{
2655 if (!s1.isEmpty())
2656 {
2657 m_t << "\\index{";
2658 m_t << latexEscapeLabelName(s1);
2659 m_t << "@{";
2660 m_t << latexEscapeIndexChars(s1);
2661 m_t << "}";
2662 if (!s2.isEmpty())
2663 {
2664 m_t << "!";
2665 m_t << latexEscapeLabelName(s2);
2666 m_t << "@{";
2667 m_t << latexEscapeIndexChars(s2);
2668 m_t << "}";
2669 }
2670 m_t << "}\n";
2671 }
2672}
QCString latexEscapeIndexChars(const QCString &s)
QCString latexEscapeLabelName(const QCString &s)

References QCString::isEmpty(), latexEscapeIndexChars(), and latexEscapeLabelName().

Referenced by LatexGenerator::addIndexItem(), LatexGenerator::endTitleHead(), LatexDocVisitor::operator()(), and LatexGenerator::startMemberDoc().

◆ writeExtraLatexPackages()

void writeExtraLatexPackages ( TextStream & t)

Definition at line 2292 of file latexgen.cpp.

2293{
2294 // User-specified packages
2295 const StringVector &extraPackages = Config_getList(EXTRA_PACKAGES);
2296 if (!extraPackages.empty())
2297 {
2298 t << "% Packages requested by user\n";
2299 for (const auto &pkgName : extraPackages)
2300 {
2301 if ((pkgName[0] == '[') || (pkgName[0] == '{'))
2302 t << "\\usepackage" << pkgName << "\n";
2303 else
2304 t << "\\usepackage{" << pkgName << "}\n";
2305 }
2306 t << "\n";
2307 }
2308}
#define Config_getList(name)
Definition config.h:38
std::vector< std::string > StringVector
Definition containers.h:33

References Config_getList.

Referenced by FormulaManager::createLatexFile(), and substituteLatexKeywords().

◆ writeLatexSpecialFormulaChars()

void writeLatexSpecialFormulaChars ( TextStream & t)

Definition at line 2310 of file latexgen.cpp.

2311{
2312 unsigned char minus[4]; // Superscript minus
2313 unsigned char sup2[3]; // Superscript two
2314 unsigned char sup3[3];
2315 minus[0]= 0xE2;
2316 minus[1]= 0x81;
2317 minus[2]= 0xBB;
2318 minus[3]= 0;
2319 sup2[0]= 0xC2;
2320 sup2[1]= 0xB2;
2321 sup2[2]= 0;
2322 sup3[0]= 0xC2;
2323 sup3[1]= 0xB3;
2324 sup3[2]= 0;
2325
2326 t << "\\ifPDFTeX\n";
2327 t << "\\usepackage{newunicodechar}\n";
2328 // taken from the newunicodechar package and removed the warning message
2329 // actually forcing to redefine the unicode character
2330 t << " \\makeatletter\n"
2331 " \\def\\doxynewunicodechar#1#2{%\n"
2332 " \\@tempswafalse\n"
2333 " \\edef\\nuc@tempa{\\detokenize{#1}}%\n"
2334 " \\if\\relax\\nuc@tempa\\relax\n"
2335 " \\nuc@emptyargerr\n"
2336 " \\else\n"
2337 " \\edef\\@tempb{\\expandafter\\@car\\nuc@tempa\\@nil}%\n"
2338 " \\nuc@check\n"
2339 " \\if@tempswa\n"
2340 " \\@namedef{u8:\\nuc@tempa}{#2}%\n"
2341 " \\fi\n"
2342 " \\fi\n"
2343 " }\n"
2344 " \\makeatother\n";
2345
2346 t << " \\doxynewunicodechar{" << minus << "}{${}^{-}$}% Superscript minus\n"
2347 " \\doxynewunicodechar{" << sup2 << "}{${}^{2}$}% Superscript two\n"
2348 " \\doxynewunicodechar{" << sup3 << "}{${}^{3}$}% Superscript three\n"
2349 "\n";
2350 t << "\\fi\n";
2351}

Referenced by FormulaManager::createLatexFile(), and substituteLatexKeywords().