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

2550{
2551 TextStream t;
2552 filterLatexString(t,s,insideTabbing,false,false,false,keepSpaces);
2553 return t.str();
2554}
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 2391 of file latexgen.cpp.

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

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

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

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

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

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

Referenced by LatexGenerator::startMemberDoc().

◆ latexFilterURL()

QCString latexFilterURL ( const QCString & s)

Definition at line 2675 of file latexgen.cpp.

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

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

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

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