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

2543{
2544 TextStream t;
2545 filterLatexString(t,s,insideTabbing,false,false,false,keepSpaces);
2546 return t.str();
2547}
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 2384 of file latexgen.cpp.

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

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

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

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

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

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

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

Referenced by LatexGenerator::startMemberDoc().

◆ latexFilterURL()

QCString latexFilterURL ( const QCString & s)

Definition at line 2668 of file latexgen.cpp.

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

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

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

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