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)

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 2542 of file latexgen.cpp.

2543{
2544 TextStream t;
2545 filterLatexString(t,s,insideTabbing,false,false,false,keepSpaces);
2546 return t.str();
2547}
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:229
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 2376 of file latexgen.cpp.

2378{
2379 if (str.isEmpty()) return;
2380 bool pdfHyperlinks = Config_getBool(PDF_HYPERLINKS);
2381 //printf("filterLatexString(%s) insideTabbing=%d\n",qPrint(str),insideTabbing);
2382 const char *p = str.data();
2383 const char *q = nullptr;
2384 unsigned char pc='\0';
2385
2386 while (*p)
2387 {
2388 unsigned char c=static_cast<unsigned char>(*p++);
2389
2390 if (insidePre)
2391 {
2392 switch(c)
2393 {
2394 case 0xef: // handle U+FFFD i.e. "Replacement character" caused by octal: 357 277 275 / hexadecimal 0xef 0xbf 0xbd
2395 // the LaTeX command \ucr has been defined in doxygen.sty
2396 if (static_cast<unsigned char>(*(p)) == 0xbf && static_cast<unsigned char>(*(p+1)) == 0xbd)
2397 {
2398 t << "{\\ucr}";
2399 p += 2;
2400 }
2401 else
2402 t << static_cast<char>(c);
2403 break;
2404 case '\\': t << "\\(\\backslash\\)"; break;
2405 case '{': t << "\\{"; break;
2406 case '}': t << "\\}"; break;
2407 case '_': t << "\\_"; break;
2408 case '&': t << "\\&"; break;
2409 case '%': t << "\\%"; break;
2410 case '#': t << "\\#"; break;
2411 case '$': t << "\\$"; break;
2412 case '"': t << "\"{}"; break;
2413 case '-': t << "-\\/"; break;
2414 case '^': insideTable ? t << "\\string^" : t << static_cast<char>(c); break;
2415 case '~': t << "\\string~"; break;
2416 case '\n': if (retainNewline) t << "\\newline"; else t << ' ';
2417 break;
2418 case ' ': if (keepSpaces) t << "~"; else t << ' ';
2419 break;
2420 default:
2421 if (c<32) t << ' '; // non printable control character
2422 else t << static_cast<char>(c);
2423 break;
2424 }
2425 }
2426 else
2427 {
2428 switch(c)
2429 {
2430 case 0xef: // handle U+FFFD i.e. "Replacement character" caused by octal: 357 277 275 / hexadecimal 0xef 0xbf 0xbd
2431 // the LaTeX command \ucr has been defined in doxygen.sty
2432 if (static_cast<unsigned char>(*(p)) == 0xbf && static_cast<unsigned char>(*(p+1)) == 0xbd)
2433 {
2434 t << "{\\ucr}";
2435 p += 2;
2436 }
2437 else
2438 t << static_cast<char>(c);
2439 break;
2440 case '#': t << "\\#"; break;
2441 case '$': t << "\\$"; break;
2442 case '%': t << "\\%"; break;
2443 case '^': processEntity(t,pdfHyperlinks,"$^\\wedge$","\\string^"); break;
2444 case '&': {
2445 // possibility to have a special symbol
2446 q = p;
2447 int cnt = 2; // we have to count & and ; as well
2448 while ((*q >= 'a' && *q <= 'z') || (*q >= 'A' && *q <= 'Z') || (*q >= '0' && *q <= '9'))
2449 {
2450 cnt++;
2451 q++;
2452 }
2453 if (*q == ';')
2454 {
2455 --p; // we need & as well
2458 {
2459 p++;
2460 t << "\\&";
2461 }
2462 else
2463 {
2465 q++;
2466 p = q;
2467 }
2468 }
2469 else
2470 {
2471 t << "\\&";
2472 }
2473 }
2474 break;
2475 case '*': processEntity(t,pdfHyperlinks,"$\\ast$","*"); break;
2476 case '_': if (!insideTabbing) t << "\\+";
2477 t << "\\_";
2478 if (!insideTabbing) t << "\\+";
2479 break;
2480 case '{': t << "\\{"; break;
2481 case '}': t << "\\}"; break;
2482 case '<': t << "$<$"; break;
2483 case '>': t << "$>$"; break;
2484 case '|': processEntity(t,pdfHyperlinks,"$\\vert$","|"); break;
2485 case '~': processEntity(t,pdfHyperlinks,"$\\sim$","\\string~"); break;
2486 case '[': if (Config_getBool(PDF_HYPERLINKS) || insideItem)
2487 t << "\\mbox{[}";
2488 else
2489 t << "[";
2490 break;
2491 case ']': if (pc=='[') t << "$\\,$";
2492 if (Config_getBool(PDF_HYPERLINKS) || insideItem)
2493 t << "\\mbox{]}";
2494 else
2495 t << "]";
2496 break;
2497 case '-': t << "-\\/";
2498 break;
2499 case '\\': t << "\\textbackslash{}";
2500 break;
2501 case '"': t << "\"{}";
2502 break;
2503 case '`': t << "\\`{}";
2504 break;
2505 case '\'': t << "\\textquotesingle{}";
2506 break;
2507 case '\n': if (retainNewline)
2508 {
2509 t << "\\newline";
2510 if (insideTable) t << " ";
2511 }
2512 else
2513 {
2514 t << ' ';
2515 }
2516 break;
2517 case ' ': if (keepSpaces) { if (insideTabbing) t << "\\>"; else t << '~'; } else t << ' ';
2518 break;
2519
2520 default:
2521 //if (!insideTabbing && forceBreaks && c!=' ' && *p!=' ')
2522 if (!insideTabbing &&
2523 ((c>='A' && c<='Z' && pc!=' ' && !(pc>='A' && pc <= 'Z') && pc!='\0' && *p) || (c==':' && pc!=':') || (pc=='.' && isId(c)))
2524 )
2525 {
2526 t << "\\+";
2527 }
2528 if (c<32)
2529 {
2530 t << ' '; // non-printable control character
2531 }
2532 else
2533 {
2534 t << static_cast<char>(c);
2535 }
2536 }
2537 }
2538 pc = c;
2539 }
2540}
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.
SymType name2sym(const QCString &symName) const
Give code of the requested HTML entity name.
This is an alternative implementation of QCString.
Definition qcstring.h:101
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:163
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:172
#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)
bool isId(int c)
Definition util.h:208

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

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

◆ latexEscapeIndexChars()

QCString latexEscapeIndexChars ( const QCString & s)

Definition at line 2594 of file latexgen.cpp.

2595{
2596 //printf("latexEscapeIndexChars(%s)\n",qPrint(s));
2597 if (s.isEmpty()) return s;
2599 TextStream t;
2600 const char *p=s.data();
2601 char c = 0;
2602 while ((c=*p++))
2603 {
2604 switch (c)
2605 {
2606 case '!': t << "\"!"; break;
2607 case '"': t << "\"\""; break;
2608 case '@': t << "\"@"; break;
2609 case '|': t << "\\texttt{\"|}"; break;
2610 case '[': t << "["; break;
2611 case ']': t << "]"; break;
2612 case '{': t << "\\lcurly{}"; break;
2613 case '}': t << "\\rcurly{}"; break;
2614 // NOTE: adding a case here, means adding it to while below as well!
2615 default:
2616 {
2617 int i=0;
2618 // collect as long string as possible, before handing it to docify
2619 tmp[i++]=c;
2620 while ((c=*p) && c!='"' && c!='@' && c!='[' && c!=']' && c!='!' && c!='{' && c!='}' && c!='|')
2621 {
2622 tmp[i++]=c;
2623 p++;
2624 }
2625 tmp[i]=0;
2626 filterLatexString(t,tmp,
2627 true, // insideTabbing
2628 false, // insidePre
2629 false, // insideItem
2630 false, // insideTable
2631 false // keepSpaces
2632 );
2633 }
2634 break;
2635 }
2636 }
2637 return t.str();
2638}
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:166
@ ExplicitSize
Definition qcstring.h:146

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

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

◆ latexEscapeLabelName()

QCString latexEscapeLabelName ( const QCString & s)

Definition at line 2549 of file latexgen.cpp.

2550{
2551 //printf("latexEscapeLabelName(%s)\n",qPrint(s));
2552 if (s.isEmpty()) return s;
2554 TextStream t;
2555 const char *p=s.data();
2556 char c = 0;
2557 while ((c=*p++))
2558 {
2559 switch (c)
2560 {
2561 case '|': t << "\\texttt{\"|}"; break;
2562 case '!': t << "\"!"; break;
2563 case '@': t << "\"@"; break;
2564 case '%': t << "\\%"; break;
2565 case '{': t << "\\lcurly{}"; break;
2566 case '}': t << "\\rcurly{}"; break;
2567 case '~': t << "````~"; break; // to get it a bit better in index together with other special characters
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!='|')
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}

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

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

◆ latexEscapePDFString()

QCString latexEscapePDFString ( const QCString & s)

Definition at line 2640 of file latexgen.cpp.

2641{
2642 if (s.isEmpty()) return s;
2643 TextStream t;
2644 const char *p=s.data();
2645 char c = 0;
2646 while ((c=*p++))
2647 {
2648 switch (c)
2649 {
2650 case '\\': t << "\\textbackslash{}"; break;
2651 case '{': t << "\\{"; break;
2652 case '}': t << "\\}"; break;
2653 case '_': t << "\\_"; break;
2654 case '%': t << "\\%"; break;
2655 case '&': t << "\\&"; break;
2656 case '#': t << "\\#"; break;
2657 case '$': t << "\\$"; break;
2658 case '^': t << "\\string^"; break;
2659 case '~': t << "\\string~"; break;
2660 default:
2661 t << c;
2662 break;
2663 }
2664 }
2665 return t.str();
2666}

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

Referenced by LatexGenerator::startMemberDoc().

◆ latexFilterURL()

QCString latexFilterURL ( const QCString & s)

Definition at line 2668 of file latexgen.cpp.

2669{
2670 constexpr auto hex = "0123456789ABCDEF";
2671 if (s.isEmpty()) return s;
2672 TextStream t;
2673 const char *p=s.data();
2674 char c = 0;
2675 while ((c=*p++))
2676 {
2677 switch (c)
2678 {
2679 case '#': t << "\\#"; break;
2680 case '%': t << "\\%"; break;
2681 case '\\': t << "\\\\"; break;
2682 default:
2683 if (c<0)
2684 {
2685 unsigned char id = static_cast<unsigned char>(c);
2686 t << "\\%" << hex[id>>4] << hex[id&0xF];
2687 }
2688 else
2689 {
2690 t << c;
2691 }
2692 break;
2693 }
2694 }
2695 return t.str();
2696}
static constexpr auto hex

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

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

◆ writeExtraLatexPackages()

void writeExtraLatexPackages ( TextStream & t)

Definition at line 2315 of file latexgen.cpp.

2316{
2317 // User-specified packages
2318 const StringVector &extraPackages = Config_getList(EXTRA_PACKAGES);
2319 if (!extraPackages.empty())
2320 {
2321 t << "% Packages requested by user\n";
2322 for (const auto &pkgName : extraPackages)
2323 {
2324 if ((pkgName[0] == '[') || (pkgName[0] == '{'))
2325 t << "\\usepackage" << pkgName << "\n";
2326 else
2327 t << "\\usepackage{" << pkgName << "}\n";
2328 }
2329 t << "\n";
2330 }
2331}
#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 2333 of file latexgen.cpp.

2334{
2335 unsigned char minus[4]; // Superscript minus
2336 unsigned char sup2[3]; // Superscript two
2337 unsigned char sup3[3];
2338 minus[0]= 0xE2;
2339 minus[1]= 0x81;
2340 minus[2]= 0xBB;
2341 minus[3]= 0;
2342 sup2[0]= 0xC2;
2343 sup2[1]= 0xB2;
2344 sup2[2]= 0;
2345 sup3[0]= 0xC2;
2346 sup3[1]= 0xB3;
2347 sup3[2]= 0;
2348
2349 t << "\\ifPDFTeX\n";
2350 t << "\\usepackage{newunicodechar}\n";
2351 // taken from the newunicodechar package and removed the warning message
2352 // actually forcing to redefine the unicode character
2353 t << " \\makeatletter\n"
2354 " \\def\\doxynewunicodechar#1#2{%\n"
2355 " \\@tempswafalse\n"
2356 " \\edef\\nuc@tempa{\\detokenize{#1}}%\n"
2357 " \\if\\relax\\nuc@tempa\\relax\n"
2358 " \\nuc@emptyargerr\n"
2359 " \\else\n"
2360 " \\edef\\@tempb{\\expandafter\\@car\\nuc@tempa\\@nil}%\n"
2361 " \\nuc@check\n"
2362 " \\if@tempswa\n"
2363 " \\@namedef{u8:\\nuc@tempa}{#2}%\n"
2364 " \\fi\n"
2365 " \\fi\n"
2366 " }\n"
2367 " \\makeatother\n";
2368
2369 t << " \\doxynewunicodechar{" << minus << "}{${}^{-}$}% Superscript minus\n"
2370 " \\doxynewunicodechar{" << sup2 << "}{${}^{2}$}% Superscript two\n"
2371 " \\doxynewunicodechar{" << sup3 << "}{${}^{3}$}% Superscript three\n"
2372 "\n";
2373 t << "\\fi\n";
2374}

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