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

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

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

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

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

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

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

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

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

Referenced by LatexGenerator::startMemberDoc().

◆ latexFilterURL()

QCString latexFilterURL ( const QCString & s)

Definition at line 2682 of file latexgen.cpp.

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

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

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

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