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

2555{
2556 TextStream t;
2557 filterLatexString(t,s,insideTabbing,false,false,false,keepSpaces);
2558 return t.str();
2559}
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 2388 of file latexgen.cpp.

2390{
2391 if (str.isEmpty()) return;
2392 bool pdfHyperlinks = Config_getBool(PDF_HYPERLINKS);
2393 //printf("filterLatexString(%s) insideTabbing=%d\n",qPrint(str),insideTabbing);
2394 const char *p = str.data();
2395 const char *q = nullptr;
2396 unsigned char pc='\0';
2397
2398 while (*p)
2399 {
2400 unsigned char c=static_cast<unsigned char>(*p++);
2401
2402 if (insidePre)
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 << "\\(\\backslash\\)"; break;
2417 case '{': t << "\\{"; break;
2418 case '}': t << "\\}"; break;
2419 case '_': t << "\\_"; break;
2420 case '&': t << "\\&"; break;
2421 case '%': t << "\\%"; break;
2422 case '#': t << "\\#"; break;
2423 case '$': t << "\\$"; break;
2424 case '"': t << "\"{}"; break;
2425 case '-': t << "-\\/"; break;
2426 case '^': insideTable ? t << "\\string^" : t << static_cast<char>(c); break;
2427 case '~': t << "\\string~"; break;
2428 case '\n': if (retainNewline) t << "\\newline"; else t << ' ';
2429 break;
2430 case ' ': if (keepSpaces) t << "~"; else t << ' ';
2431 break;
2432 default:
2433 if (c<32) t << ' '; // non printable control character
2434 else t << static_cast<char>(c);
2435 break;
2436 }
2437 }
2438 else
2439 {
2440 switch(c)
2441 {
2442 case 0xef: // handle U+FFFD i.e. "Replacement character" caused by octal: 357 277 275 / hexadecimal 0xef 0xbf 0xbd
2443 // the LaTeX command \ucr has been defined in doxygen.sty
2444 if (static_cast<unsigned char>(*(p)) == 0xbf && static_cast<unsigned char>(*(p+1)) == 0xbd)
2445 {
2446 t << "{\\ucr}";
2447 p += 2;
2448 }
2449 else
2450 t << static_cast<char>(c);
2451 break;
2452 case '#': t << "\\#"; break;
2453 case '$': t << "\\$"; break;
2454 case '%': t << "\\%"; break;
2455 case '^': processEntity(t,pdfHyperlinks,"$^\\wedge$","\\string^"); break;
2456 case '&': {
2457 // possibility to have a special symbol
2458 q = p;
2459 int cnt = 2; // we have to count & and ; as well
2460 while ((*q >= 'a' && *q <= 'z') || (*q >= 'A' && *q <= 'Z') || (*q >= '0' && *q <= '9'))
2461 {
2462 cnt++;
2463 q++;
2464 }
2465 if (*q == ';')
2466 {
2467 --p; // we need & as well
2470 {
2471 p++;
2472 t << "\\&";
2473 }
2474 else
2475 {
2477 q++;
2478 p = q;
2479 }
2480 }
2481 else
2482 {
2483 t << "\\&";
2484 }
2485 }
2486 break;
2487 case '*': processEntity(t,pdfHyperlinks,"$\\ast$","*"); break;
2488 case '_': if (!insideTabbing) t << "\\+";
2489 t << "\\_";
2490 if (!insideTabbing) t << "\\+";
2491 break;
2492 case '{': t << "\\{"; break;
2493 case '}': t << "\\}"; break;
2494 case '<': t << "$<$"; break;
2495 case '>': t << "$>$"; break;
2496 case '|': processEntity(t,pdfHyperlinks,"$\\vert$","|"); break;
2497 case '~': processEntity(t,pdfHyperlinks,"$\\sim$","\\string~"); break;
2498 case '[': if (Config_getBool(PDF_HYPERLINKS) || insideItem)
2499 t << "\\mbox{[}";
2500 else
2501 t << "[";
2502 break;
2503 case ']': if (pc=='[') t << "$\\,$";
2504 if (Config_getBool(PDF_HYPERLINKS) || insideItem)
2505 t << "\\mbox{]}";
2506 else
2507 t << "]";
2508 break;
2509 case '-': t << "-\\/";
2510 break;
2511 case '\\': t << "\\textbackslash{}";
2512 break;
2513 case '"': t << "\"{}";
2514 break;
2515 case '`': t << "\\`{}";
2516 break;
2517 case '\'': t << "\\textquotesingle{}";
2518 break;
2519 case '\n': if (retainNewline)
2520 {
2521 t << "\\newline";
2522 if (insideTable) t << " ";
2523 }
2524 else
2525 {
2526 t << ' ';
2527 }
2528 break;
2529 case ' ': if (keepSpaces) { if (insideTabbing) t << "\\>"; else t << '~'; } else t << ' ';
2530 break;
2531
2532 default:
2533 //if (!insideTabbing && forceBreaks && c!=' ' && *p!=' ')
2534 if (!insideTabbing &&
2535 ((c>='A' && c<='Z' && pc!=' ' && !(pc>='A' && pc <= 'Z') && pc!='\0' && *p) || (c==':' && pc!=':') || (pc=='.' && isId(c)))
2536 )
2537 {
2538 t << "\\+";
2539 }
2540 if (c<32)
2541 {
2542 t << ' '; // non-printable control character
2543 }
2544 else
2545 {
2546 t << static_cast<char>(c);
2547 }
2548 }
2549 }
2550 pc = c;
2551 }
2552}
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 2606 of file latexgen.cpp.

2607{
2608 //printf("latexEscapeIndexChars(%s)\n",qPrint(s));
2609 if (s.isEmpty()) return s;
2611 TextStream t;
2612 const char *p=s.data();
2613 char c = 0;
2614 while ((c=*p++))
2615 {
2616 switch (c)
2617 {
2618 case '!': t << "\"!"; break;
2619 case '"': t << "\"\""; break;
2620 case '@': t << "\"@"; break;
2621 case '|': t << "\\texttt{\"|}"; break;
2622 case '[': t << "["; break;
2623 case ']': t << "]"; break;
2624 case '{': t << "\\lcurly{}"; break;
2625 case '}': t << "\\rcurly{}"; break;
2626 // NOTE: adding a case here, means adding it to while below as well!
2627 default:
2628 {
2629 int i=0;
2630 // collect as long string as possible, before handing it to docify
2631 tmp[i++]=c;
2632 while ((c=*p) && c!='"' && c!='@' && c!='[' && c!=']' && c!='!' && c!='{' && c!='}' && c!='|')
2633 {
2634 tmp[i++]=c;
2635 p++;
2636 }
2637 tmp[i]=0;
2638 filterLatexString(t,tmp,
2639 true, // insideTabbing
2640 false, // insidePre
2641 false, // insideItem
2642 false, // insideTable
2643 false // keepSpaces
2644 );
2645 }
2646 break;
2647 }
2648 }
2649 return t.str();
2650}
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 2561 of file latexgen.cpp.

2562{
2563 //printf("latexEscapeLabelName(%s)\n",qPrint(s));
2564 if (s.isEmpty()) return s;
2566 TextStream t;
2567 const char *p=s.data();
2568 char c = 0;
2569 while ((c=*p++))
2570 {
2571 switch (c)
2572 {
2573 case '|': t << "\\texttt{\"|}"; break;
2574 case '!': t << "\"!"; break;
2575 case '@': t << "\"@"; break;
2576 case '%': t << "\\%"; break;
2577 case '{': t << "\\lcurly{}"; break;
2578 case '}': t << "\\rcurly{}"; break;
2579 case '~': t << "````~"; break; // to get it a bit better in index together with other special characters
2580 // NOTE: adding a case here, means adding it to while below as well!
2581 default:
2582 {
2583 int i=0;
2584 // collect as long string as possible, before handing it to docify
2585 tmp[i++]=c;
2586 while ((c=*p) && c!='@' && c!='[' && c!=']' && c!='!' && c!='{' && c!='}' && c!='|')
2587 {
2588 tmp[i++]=c;
2589 p++;
2590 }
2591 tmp[i]=0;
2592 filterLatexString(t,tmp,
2593 true, // insideTabbing
2594 false, // insidePre
2595 false, // insideItem
2596 false, // insideTable
2597 false // keepSpaces
2598 );
2599 }
2600 break;
2601 }
2602 }
2603 return t.str();
2604}

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

2653{
2654 if (s.isEmpty()) return s;
2655 TextStream t;
2656 const char *p=s.data();
2657 char c = 0;
2658 while ((c=*p++))
2659 {
2660 switch (c)
2661 {
2662 case '\\': t << "\\textbackslash{}"; break;
2663 case '{': t << "\\{"; break;
2664 case '}': t << "\\}"; break;
2665 case '_': t << "\\_"; break;
2666 case '%': t << "\\%"; break;
2667 case '&': t << "\\&"; break;
2668 case '#': t << "\\#"; break;
2669 case '$': t << "\\$"; break;
2670 case '^': t << "\\string^"; break;
2671 case '~': t << "\\string~"; break;
2672 default:
2673 t << c;
2674 break;
2675 }
2676 }
2677 return t.str();
2678}

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

Referenced by LatexGenerator::startMemberDoc().

◆ latexFilterURL()

QCString latexFilterURL ( const QCString & s)

Definition at line 2680 of file latexgen.cpp.

2681{
2682 constexpr auto hex = "0123456789ABCDEF";
2683 if (s.isEmpty()) return s;
2684 TextStream t;
2685 const char *p=s.data();
2686 char c = 0;
2687 while ((c=*p++))
2688 {
2689 switch (c)
2690 {
2691 case '#': t << "\\#"; break;
2692 case '%': t << "\\%"; break;
2693 case '\\': t << "\\\\"; break;
2694 default:
2695 if (c<0)
2696 {
2697 unsigned char id = static_cast<unsigned char>(c);
2698 t << "\\%" << hex[id>>4] << hex[id&0xF];
2699 }
2700 else
2701 {
2702 t << c;
2703 }
2704 break;
2705 }
2706 }
2707 return t.str();
2708}
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 2327 of file latexgen.cpp.

2328{
2329 // User-specified packages
2330 const StringVector &extraPackages = Config_getList(EXTRA_PACKAGES);
2331 if (!extraPackages.empty())
2332 {
2333 t << "% Packages requested by user\n";
2334 for (const auto &pkgName : extraPackages)
2335 {
2336 if ((pkgName[0] == '[') || (pkgName[0] == '{'))
2337 t << "\\usepackage" << pkgName << "\n";
2338 else
2339 t << "\\usepackage{" << pkgName << "}\n";
2340 }
2341 t << "\n";
2342 }
2343}
#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 2345 of file latexgen.cpp.

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

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