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

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

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

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

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

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

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

2652{
2653 if (s.isEmpty()) return s;
2654 TextStream t;
2655 const char *p=s.data();
2656 char c = 0;
2657 while ((c=*p++))
2658 {
2659 switch (c)
2660 {
2661 case '\\': t << "\\textbackslash{}"; break;
2662 case '{': t << "\\{"; 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 << "\\string^"; break;
2670 case '~': t << "\\string~"; break;
2671 default:
2672 t << c;
2673 break;
2674 }
2675 }
2676 return t.str();
2677}

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

Referenced by LatexGenerator::startMemberDoc().

◆ latexFilterURL()

QCString latexFilterURL ( const QCString & s)

Definition at line 2679 of file latexgen.cpp.

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

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

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

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