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

2547{
2548 TextStream t;
2549 filterLatexString(t,s,insideTabbing,false,false,false,keepSpaces);
2550 return t.str();
2551}
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) t << "\\newline"; else t << ' ';
2520 break;
2521 case ' ': if (keepSpaces) { if (insideTabbing) t << "\\>"; else t << '~'; } else t << ' ';
2522 break;
2523
2524 default:
2525 //if (!insideTabbing && forceBreaks && c!=' ' && *p!=' ')
2526 if (!insideTabbing &&
2527 ((c>='A' && c<='Z' && pc!=' ' && !(pc>='A' && pc <= 'Z') && pc!='\0' && *p) || (c==':' && pc!=':') || (pc=='.' && isId(c)))
2528 )
2529 {
2530 t << "\\+";
2531 }
2532 if (c<32)
2533 {
2534 t << ' '; // non-printable control character
2535 }
2536 else
2537 {
2538 t << static_cast<char>(c);
2539 }
2540 }
2541 }
2542 pc = c;
2543 }
2544}
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 2598 of file latexgen.cpp.

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

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

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

2645{
2646 if (s.isEmpty()) return s;
2647 TextStream t;
2648 const char *p=s.data();
2649 char c = 0;
2650 while ((c=*p++))
2651 {
2652 switch (c)
2653 {
2654 case '\\': t << "\\textbackslash{}"; 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 << "\\$"; break;
2662 case '^': t << "\\string^"; break;
2663 case '~': t << "\\string~"; break;
2664 default:
2665 t << c;
2666 break;
2667 }
2668 }
2669 return t.str();
2670}

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

Referenced by LatexGenerator::startMemberDoc().

◆ latexFilterURL()

QCString latexFilterURL ( const QCString & s)

Definition at line 2672 of file latexgen.cpp.

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