Doxygen
Loading...
Searching...
No Matches
latexgen.h File Reference

#include <src/latexgen.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...

Namespaces

namespace  LatexSections
 LaTeX sectioning commands of doxygen.sty, indexed by nesting level.

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="")
const char * LatexSections::name (int level)

Variables

constexpr std::array LatexSections::labels
constexpr int LatexSections::maxLevels = static_cast<int>(labels.size())

Macro Definition Documentation

◆ LATEX_STYLE_EXTENSION

#define LATEX_STYLE_EXTENSION   ".sty"

Definition at line 24 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 2508 of file latexgen.cpp.

2509{
2510 TextStream t;
2511 filterLatexString(t,s,insideTabbing,false,false,false,keepSpaces);
2512 return t.str();
2513}
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 2361 of file latexgen.cpp.

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

2561{
2562 //printf("latexEscapeIndexChars(%s)\n",qPrint(s));
2563 if (s.empty()) return s;
2565 TextStream t;
2566 const char *p=s.data();
2567 char c = 0;
2568 while ((c=*p++))
2569 {
2570 switch (c)
2571 {
2572 case '!': t << "\"!"; break;
2573 case '"': t << "\"\""; break;
2574 case '@': t << "\"@"; break;
2575 case '|': t << "\\texttt{\"|}"; break;
2576 case '[': t << "["; break;
2577 case ']': t << "]"; break;
2578 case '{': t << "\\lcurly{}"; break;
2579 case '}': t << "\\rcurly{}"; break;
2580 // NOTE: adding a case here, means adding it to while below as well!
2581 default:
2582 {
2583 int i=0;
2584 // collect as long string as possible, before handing it to docify
2585 tmp[i++]=c;
2586 while ((c=*p) && c!='"' && c!='@' && c!='[' && c!=']' && c!='!' && c!='{' && c!='}' && c!='|')
2587 {
2588 tmp[i++]=c;
2589 p++;
2590 }
2591 tmp[i]=0;
2592 filterLatexString(t,tmp,
2593 true, // insideTabbing
2594 false, // insidePre
2595 false, // insideItem
2596 false, // insideTable
2597 false // keepSpaces
2598 );
2599 }
2600 break;
2601 }
2602 }
2603 return t.str();
2604}
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
@ ExplicitSize
Definition dstring.h:131
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:151

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

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

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

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

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

Referenced by LatexGenerator::startMemberDoc().

◆ latexFilterURL()

DString latexFilterURL ( const DString & s)

Definition at line 2634 of file latexgen.cpp.

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

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

2666{
2667 if (!s1.empty())
2668 {
2669 m_t << "\\index{";
2670 m_t << latexEscapeLabelName(s1);
2671 m_t << "@{";
2672 m_t << latexEscapeIndexChars(s1);
2673 m_t << "}";
2674 if (!s2.empty())
2675 {
2676 m_t << "!";
2677 m_t << latexEscapeLabelName(s2);
2678 m_t << "@{";
2679 m_t << latexEscapeIndexChars(s2);
2680 m_t << "}";
2681 }
2682 m_t << "}\n";
2683 }
2684}
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 2300 of file latexgen.cpp.

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

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

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