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

2546{
2547 TextStream t;
2548 filterLatexString(t,s,insideTabbing,false,false,false,keepSpaces);
2549 return t.str();
2550}
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 2387 of file latexgen.cpp.

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

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

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

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

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

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

Referenced by LatexGenerator::startMemberDoc().

◆ latexFilterURL()

QCString latexFilterURL ( const QCString & s)

Definition at line 2671 of file latexgen.cpp.

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

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

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

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