Doxygen
Loading...
Searching...
No Matches
latexgen.h File Reference
#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)
DString convertToLaTeX (const DString &s, bool insideTabbing, bool keepSpaces=false)
void filterLatexString (TextStream &t, const DString &str, bool insideTabbing, bool insidePre, bool insideItem, bool insideTable, bool keepSpaces, const bool retainNewline=false)
DString latexEscapeLabelName (const DString &s)
DString latexEscapeIndexChars (const DString &s)
DString latexEscapePDFString (const DString &s)
DString latexFilterURL (const DString &s)
void latexWriteIndexItem (TextStream &t, const DString &r1, const DString &s2="")

Macro Definition Documentation

◆ LATEX_STYLE_EXTENSION

#define LATEX_STYLE_EXTENSION   ".sty"

Definition at line 21 of file latexgen.h.

Referenced by copyLatexStyleSheet(), and extraLatexStyleSheet().

Function Documentation

◆ convertToLaTeX()

DString convertToLaTeX ( const DString & s,
bool insideTabbing,
bool keepSpaces = false )

Definition at line 2510 of file latexgen.cpp.

2511{
2512 TextStream t;
2513 filterLatexString(t,s,insideTabbing,false,false,false,keepSpaces);
2514 return t.str();
2515}
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:232
void filterLatexString(TextStream &t, const DString &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 DString & str,
bool insideTabbing,
bool insidePre,
bool insideItem,
bool insideTable,
bool keepSpaces,
const bool retainNewline = false )

Definition at line 2363 of file latexgen.cpp.

2365{
2366 if (str.empty()) return;
2367 bool pdfHyperlinks = Config_getBool(PDF_HYPERLINKS);
2368 //printf("filterLatexString(%s) insideTabbing=%d\n",qPrint(str),insideTabbing);
2369 const char *p = str.data();
2370 unsigned char pc='\0';
2371
2372 while (*p)
2373 {
2374 unsigned char c=static_cast<unsigned char>(*p++);
2375
2376 if (insidePre)
2377 {
2378 switch(c)
2379 {
2380 case 0xef: // handle U+FFFD i.e. "Replacement character" caused by octal: 357 277 275 / hexadecimal 0xef 0xbf 0xbd
2381 // the LaTeX command \ucr has been defined in doxygen.sty
2382 if (static_cast<unsigned char>(*(p)) == 0xbf && static_cast<unsigned char>(*(p+1)) == 0xbd)
2383 {
2384 t << "{\\ucr}";
2385 p += 2;
2386 }
2387 else
2388 t << static_cast<char>(c);
2389 break;
2390 case '\\': t << "\\(\\backslash\\)"; break;
2391 case '{': t << "\\{"; break;
2392 case '}': t << "\\}"; break;
2393 case '_': t << "\\_"; break;
2394 case '&': t << "\\&"; break;
2395 case '%': t << "\\%"; break;
2396 case '#': t << "\\#"; break;
2397 case '$': t << "\\$"; break;
2398 case '"': t << "\"{}"; break;
2399 case '-': t << "-\\/"; break;
2400 case '^': insideTable ? t << "\\string^" : t << static_cast<char>(c); break;
2401 case '~': t << "\\string~"; break;
2402 case '\n': if (retainNewline) t << "\\newline"; else t << ' ';
2403 break;
2404 case ' ': if (keepSpaces) t << "~"; else t << ' ';
2405 break;
2406 default:
2407 if (c<32) t << ' '; // non printable control character
2408 else t << static_cast<char>(c);
2409 break;
2410 }
2411 }
2412 else
2413 {
2414 switch(c)
2415 {
2416 case 0xef: // handle U+FFFD i.e. "Replacement character" caused by octal: 357 277 275 / hexadecimal 0xef 0xbf 0xbd
2417 // the LaTeX command \ucr has been defined in doxygen.sty
2418 if (static_cast<unsigned char>(*(p)) == 0xbf && static_cast<unsigned char>(*(p+1)) == 0xbd)
2419 {
2420 t << "{\\ucr}";
2421 p += 2;
2422 }
2423 else
2424 t << static_cast<char>(c);
2425 break;
2426 case '#': t << "\\+\\#"; break;
2427 case '$': t << "\\$"; break;
2428 case '%': t << "\\%"; break;
2429 case '^': processEntity(t,pdfHyperlinks,"$^\\wedge$","\\string^"); break;
2430 case '&': {
2431 // possibility to have a special symbol
2433 t,
2434 p-1,
2435 [](HtmlEntityMapper::SymType symType) { return HtmlEntityMapper::instance().latex(symType); },
2436 "\\&");
2437 }
2438 break;
2439 case '*': processEntity(t,pdfHyperlinks,"$\\ast$","*"); break;
2440 case '_': if (!insideTabbing && *p) t << "\\+";
2441 t << "\\_";
2442 if (!insideTabbing && *p) t << "\\+";
2443 break;
2444 case '{': t << "\\{"; break;
2445 case '}': t << "\\}"; break;
2446 case '<': t << "$<$"; break;
2447 case '>': t << "$>$"; break;
2448 case '|': processEntity(t,pdfHyperlinks,"$\\vert$","|"); break;
2449 case '~': processEntity(t,pdfHyperlinks,"$\\sim$","\\string~"); break;
2450 case '[': if (Config_getBool(PDF_HYPERLINKS) || insideItem)
2451 t << "\\+[";
2452 else
2453 t << "[";
2454 break;
2455 case ']': if (pc=='[') t << "$\\,$";
2456 if ((Config_getBool(PDF_HYPERLINKS) || insideItem) && *p)
2457 t << "]\\+";
2458 else
2459 t << "]";
2460 break;
2461 case '-': t << "-\\/";
2462 break;
2463 case '\\': t << "\\textbackslash{}";
2464 break;
2465 case '"': t << "\"{}";
2466 break;
2467 case '`': t << "\\`{}";
2468 break;
2469 case '\'': t << "\\textquotesingle{}";
2470 break;
2471 case '\n': if (retainNewline)
2472 {
2473 t << "\\newline";
2474 if (insideTable) t << " ";
2475 }
2476 else
2477 {
2478 t << ' ';
2479 }
2480 break;
2481 case ' ': if (keepSpaces) { if (insideTabbing) t << "\\>"; else t << '~'; } else t << ' ';
2482 break;
2483
2484 default:
2485 //if (!insideTabbing && forceBreaks && c!=' ' && *p!=' ')
2486 if (!insideTabbing &&
2487 ((c>='A' && c<='Z' && pc!=' ' && !(pc>='A' && pc <= 'Z') && pc!='\0' && *p) || (pc=='.' && isId(c)))
2488 )
2489 {
2490 t << "\\+";
2491 }
2492 if (c<32)
2493 {
2494 t << ' '; // non-printable control character
2495 }
2496 else
2497 {
2498 t << static_cast<char>(c);
2499 }
2500 if (!insideTabbing && *p && ((c==':' && *p!=':') || c=='/'))
2501 {
2502 t << "\\+";
2503 }
2504 }
2505 }
2506 pc = c;
2507 }
2508}
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:152
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition dstring.h:161
const char * latex(SymType symb) const
Access routine to the LaTeX code of the HTML entity.
const char * writeHtmlEntity(T &result, const char *s, HtmlEntityMapperFunc &&mapper, const char *fallback)
Definition htmlentity.h:127
static HtmlEntityMapper & instance()
Returns the one and only instance of the HTML entity mapper.
#define Config_getBool(name)
Definition config.h:33
bool insideTable(const DocNodeVariant *n)
bool isId(int c)
Returns true if c is a valid character for an identifier.
Definition dstring.h:899
static void processEntity(TextStream &t, bool pdfHyperlinks, const char *strForm, const char *strRepl)

References Config_getBool, DString::data(), DString::empty(), insideTable(), HtmlEntityMapper::instance(), isId(), HtmlEntityMapper::latex(), processEntity(), and HtmlEntityMapper::writeHtmlEntity().

Referenced by LatexCodeGenerator::codify(), convertToLaTeX(), LatexGenerator::docify(), LatexDocVisitor::filter(), latexEscapeIndexChars(), latexEscapeLabelName(), and substituteLatexKeywords().

◆ latexEscapeIndexChars()

DString latexEscapeIndexChars ( const DString & s)

Definition at line 2562 of file latexgen.cpp.

2563{
2564 //printf("latexEscapeIndexChars(%s)\n",qPrint(s));
2565 if (s.empty()) return s;
2567 TextStream t;
2568 const char *p=s.data();
2569 char c = 0;
2570 while ((c=*p++))
2571 {
2572 switch (c)
2573 {
2574 case '!': t << "\"!"; break;
2575 case '"': t << "\"\""; break;
2576 case '@': t << "\"@"; break;
2577 case '|': t << "\\texttt{\"|}"; break;
2578 case '[': t << "["; break;
2579 case ']': t << "]"; break;
2580 case '{': t << "\\lcurly{}"; break;
2581 case '}': t << "\\rcurly{}"; break;
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!='}' && 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}
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:88
@ ExplicitSize
Definition dstring.h:135
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:155

References DString::data(), DString::empty(), DString::ExplicitSize, filterLatexString(), DString::length(), and TextStream::str().

Referenced by latexWriteIndexItem(), and LatexGenerator::startMemberDoc().

◆ latexEscapeLabelName()

DString latexEscapeLabelName ( const DString & s)

Definition at line 2517 of file latexgen.cpp.

2518{
2519 //printf("latexEscapeLabelName(%s)\n",qPrint(s));
2520 if (s.empty()) return s;
2522 TextStream t;
2523 const char *p=s.data();
2524 char c = 0;
2525 while ((c=*p++))
2526 {
2527 switch (c)
2528 {
2529 case '|': t << "\\texttt{\"|}"; break;
2530 case '!': t << "\"!"; break;
2531 case '@': t << "\"@"; break;
2532 case '%': t << "\\%"; break;
2533 case '{': t << "\\lcurly{}"; break;
2534 case '}': t << "\\rcurly{}"; break;
2535 case '~': t << "````~"; break; // to get it a bit better in index together with other special characters
2536 // NOTE: adding a case here, means adding it to while below as well!
2537 default:
2538 {
2539 int i=0;
2540 // collect as long string as possible, before handing it to docify
2541 tmp[i++]=c;
2542 while ((c=*p) && c!='@' && c!='[' && c!=']' && c!='!' && c!='{' && c!='}' && c!='|')
2543 {
2544 tmp[i++]=c;
2545 p++;
2546 }
2547 tmp[i]=0;
2548 filterLatexString(t,tmp,
2549 true, // insideTabbing
2550 false, // insidePre
2551 false, // insideItem
2552 false, // insideTable
2553 false // keepSpaces
2554 );
2555 }
2556 break;
2557 }
2558 }
2559 return t.str();
2560}

References DString::data(), DString::empty(), DString::ExplicitSize, filterLatexString(), DString::length(), and TextStream::str().

Referenced by latexWriteIndexItem().

◆ latexEscapePDFString()

DString latexEscapePDFString ( const DString & s)

Definition at line 2608 of file latexgen.cpp.

2609{
2610 if (s.empty()) return s;
2611 TextStream t;
2612 const char *p=s.data();
2613 char c = 0;
2614 while ((c=*p++))
2615 {
2616 switch (c)
2617 {
2618 case '\\': t << "\\textbackslash{}"; break;
2619 case '{': t << "\\{"; break;
2620 case '}': t << "\\}"; break;
2621 case '_': t << "\\_"; break;
2622 case '%': t << "\\%"; break;
2623 case '&': t << "\\&"; break;
2624 case '#': t << "\\#"; break;
2625 case '$': t << "\\$"; break;
2626 case '^': t << "\\string^"; break;
2627 case '~': t << "\\string~"; break;
2628 default:
2629 t << c;
2630 break;
2631 }
2632 }
2633 return t.str();
2634}

References DString::data(), DString::empty(), and TextStream::str().

Referenced by LatexGenerator::startMemberDoc().

◆ latexFilterURL()

DString latexFilterURL ( const DString & s)

Definition at line 2636 of file latexgen.cpp.

2637{
2638 constexpr auto hex = "0123456789ABCDEF";
2639 if (s.empty()) return s;
2640 TextStream t;
2641 const char *p=s.data();
2642 char c = 0;
2643 while ((c=*p++))
2644 {
2645 switch (c)
2646 {
2647 case '#': t << "\\#"; break;
2648 case '%': t << "\\%"; break;
2649 case '\\': t << "\\\\"; break;
2650 case '\n': break; // ignore
2651 default:
2652 if (c<0)
2653 {
2654 unsigned char id = static_cast<unsigned char>(c);
2655 t << "\\%" << hex[id>>4] << hex[id&0xF];
2656 }
2657 else
2658 {
2659 t << c;
2660 }
2661 break;
2662 }
2663 }
2664 return t.str();
2665}

References DString::data(), DString::empty(), and TextStream::str().

Referenced by LatexDocVisitor::operator()(), and LatexDocVisitor::operator()().

◆ latexWriteIndexItem()

void latexWriteIndexItem ( TextStream & t,
const DString & r1,
const DString & s2 = "" )

Definition at line 2667 of file latexgen.cpp.

2668{
2669 if (!s1.empty())
2670 {
2671 m_t << "\\index{";
2672 m_t << latexEscapeLabelName(s1);
2673 m_t << "@{";
2674 m_t << latexEscapeIndexChars(s1);
2675 m_t << "}";
2676 if (!s2.empty())
2677 {
2678 m_t << "!";
2679 m_t << latexEscapeLabelName(s2);
2680 m_t << "@{";
2681 m_t << latexEscapeIndexChars(s2);
2682 m_t << "}";
2683 }
2684 m_t << "}\n";
2685 }
2686}
DString latexEscapeIndexChars(const DString &s)
DString latexEscapeLabelName(const DString &s)

References DString::empty(), latexEscapeIndexChars(), and latexEscapeLabelName().

Referenced by LatexGenerator::addIndexItem(), LatexGenerator::endTitleHead(), LatexDocVisitor::operator()(), and LatexGenerator::startMemberDoc().

◆ writeExtraLatexPackages()

void writeExtraLatexPackages ( TextStream & t)

Definition at line 2302 of file latexgen.cpp.

2303{
2304 // User-specified packages
2305 StringVector extraPackages = Config_getList(EXTRA_PACKAGES);
2306 if (!extraPackages.empty())
2307 {
2308 t << "% Packages requested by user\n";
2309 for (const auto &pkgName : extraPackages)
2310 {
2311 if ((pkgName[0] == '[') || (pkgName[0] == '{'))
2312 t << "\\usepackage" << pkgName << "\n";
2313 else
2314 t << "\\usepackage{" << pkgName << "}\n";
2315 }
2316 t << "\n";
2317 }
2318}
#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 2320 of file latexgen.cpp.

2321{
2322 unsigned char minus[4]; // Superscript minus
2323 unsigned char sup2[3]; // Superscript two
2324 unsigned char sup3[3];
2325 minus[0]= 0xE2;
2326 minus[1]= 0x81;
2327 minus[2]= 0xBB;
2328 minus[3]= 0;
2329 sup2[0]= 0xC2;
2330 sup2[1]= 0xB2;
2331 sup2[2]= 0;
2332 sup3[0]= 0xC2;
2333 sup3[1]= 0xB3;
2334 sup3[2]= 0;
2335
2336 t << "\\ifPDFTeX\n";
2337 t << "\\usepackage{newunicodechar}\n";
2338 // taken from the newunicodechar package and removed the warning message
2339 // actually forcing to redefine the unicode character
2340 t << " \\makeatletter\n"
2341 " \\def\\doxynewunicodechar#1#2{%\n"
2342 " \\@tempswafalse\n"
2343 " \\edef\\nuc@tempa{\\detokenize{#1}}%\n"
2344 " \\if\\relax\\nuc@tempa\\relax\n"
2345 " \\nuc@emptyargerr\n"
2346 " \\else\n"
2347 " \\edef\\@tempb{\\expandafter\\@car\\nuc@tempa\\@nil}%\n"
2348 " \\nuc@check\n"
2349 " \\if@tempswa\n"
2350 " \\@namedef{u8:\\nuc@tempa}{#2}%\n"
2351 " \\fi\n"
2352 " \\fi\n"
2353 " }\n"
2354 " \\makeatother\n";
2355
2356 t << " \\doxynewunicodechar{" << minus << "}{${}^{-}$}% Superscript minus\n"
2357 " \\doxynewunicodechar{" << sup2 << "}{${}^{2}$}% Superscript two\n"
2358 " \\doxynewunicodechar{" << sup3 << "}{${}^{3}$}% Superscript three\n"
2359 "\n";
2360 t << "\\fi\n";
2361}

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