From f4544b7508bde732dacb1172e8200e88ac07c82b Mon Sep 17 00:00:00 2001 From: albert-github Date: Tue, 22 May 2018 18:45:20 +0200 Subject: Small problems when having code in LaTeX output - in formulas it is also possible to have special characters - adding special character '-' for U+2212 - making special characters more system independent (plain latex was not handled) and should be independent of hyperlink setting - without hyperlinks the name of normally linked names with underscore kept e.g. their underscores instead of escaping it - be sure that on the end of a code section the previous line is properly 'closed'. --- src/formula.cpp | 2 ++ src/latexgen.cpp | 37 +++++++------------------------------ src/util.cpp | 35 +++++++++++++++++++++++++++++++++++ src/util.h | 1 + 4 files changed, 45 insertions(+), 30 deletions(-) diff --git a/src/formula.cpp b/src/formula.cpp index 6fe617d..4644f12 100644 --- a/src/formula.cpp +++ b/src/formula.cpp @@ -69,8 +69,10 @@ void FormulaList::generateBitmaps(const char *path) FTextStream t(&f); if (Config_getBool(LATEX_BATCHMODE)) t << "\\batchmode" << endl; t << "\\documentclass{article}" << endl; + t << "\\usepackage{ifthen}" << endl; t << "\\usepackage{epsfig}" << endl; // for those who want to include images writeExtraLatexPackages(t); + writeLatexSpecialFormulaChars(t); t << "\\pagestyle{empty}" << endl; t << "\\begin{document}" << endl; int page=0; diff --git a/src/latexgen.cpp b/src/latexgen.cpp index 00826e6..a3cdaa8 100644 --- a/src/latexgen.cpp +++ b/src/latexgen.cpp @@ -181,7 +181,7 @@ void LatexCodeGenerator::writeCodeLink(const char *ref,const char *f, } else { - m_t << name; + codify(name); } m_col+=l; } @@ -633,46 +633,18 @@ static void writeDefaultHeaderPart1(FTextStream &t) "\n"; writeExtraLatexPackages(t); + writeLatexSpecialFormulaChars(t); // Hyperlinks bool pdfHyperlinks = Config_getBool(PDF_HYPERLINKS); if (pdfHyperlinks) { - unsigned char minus[4]; // Superscript minus - char *pminus = (char *)minus; - unsigned char sup2[3]; // Superscript two - char *psup2 = (char *)sup2; - unsigned char sup3[3]; - char *psup3 = (char *)sup3; // Superscript three - minus[0]= 0xE2; - minus[1]= 0x81; - minus[2]= 0xBB; - minus[3]= 0; - sup2[0]= 0xC2; - sup2[1]= 0xB2; - sup2[2]= 0; - sup3[0]= 0xC2; - sup3[1]= 0xB3; - sup3[2]= 0; - t << "% Hyperlinks (required, but should be loaded last)\n" "\\ifpdf\n" " \\usepackage[pdftex,pagebackref=true]{hyperref}\n" "\\else\n" " \\usepackage[ps2pdf,pagebackref=true]{hyperref}\n" "\\fi\n" - "\\ifpdf\n" - " \\DeclareUnicodeCharacter{207B}{${}^{-}$}% Superscript minus\n" - " \\DeclareUnicodeCharacter{C2B2}{${}^{2}$}% Superscript two\n" - " \\DeclareUnicodeCharacter{C2B3}{${}^{3}$}% Superscript three\n" - "\\else\n" - " \\catcode`\\" << pminus << "=13% Superscript minus\n" - " \\def" << pminus << "{${}^{-}$}\n" - " \\catcode`\\" << psup2 << "=13% Superscript two\n" - " \\def" << psup2 << "{${}^{2}$}\n" - " \\catcode`\\"<