From fd3b60caa8bb99bec81b74d74f394c6043091c76 Mon Sep 17 00:00:00 2001 From: albert-github Date: Tue, 27 Aug 2019 16:55:47 +0200 Subject: Create possibility to define LaTeX commands for formulas To be able to have building bocks for formulas one can create a `\newcommand` (or when one wants to change a command `\renewcommand`). Due to the different handling of LaTeX commands in pure LaTeX code (latex output and formulas converted to images) and MathJax it is necessary to transform LaTeX commands to the MathJax equivalent. This is done in a transparent way by providing the new commands in a file and add this verbatim to the pure LaTeX code and to translate the `\newcommand` and `\renewcomamnd` to MathJax macros. --- addon/doxywizard/expert.cpp | 3 + doc/formulas.doc | 20 ++++- src/config.xml | 10 +++ src/configgen.py | 2 + src/formula.cpp | 14 ++++ src/htmlgen.cpp | 185 +++++++++++++++++++++++++++++++++++++++++++- src/latexgen.cpp | 10 +++ 7 files changed, 242 insertions(+), 2 deletions(-) diff --git a/addon/doxywizard/expert.cpp b/addon/doxywizard/expert.cpp index 64df27f..1303a22 100644 --- a/addon/doxywizard/expert.cpp +++ b/addon/doxywizard/expert.cpp @@ -398,6 +398,7 @@ static QString getDocsForNode(const QDomElement &child) // Remove / replace doxygen markup strings // the regular expressions are hard to read so the intention will be given + // Note: see also configgen.py in the src directory for other doxygen parts QRegExp regexp; // remove \n at end and replace by a space regexp.setPattern(SA("\\n$")); @@ -432,6 +433,8 @@ static QString getDocsForNode(const QDomElement &child) docs.replace(regexp,SA("\"External Indexing and Searching\"")); regexp.setPattern(SA("\\\\ref[ ]+external")); docs.replace(regexp,SA("\"Linking to external documentation\"")); + regexp.setPattern(SA("\\\\ref[ ]+formulas")); + docs.replace(regexp,SA("\"Including formulas\"")); // fallback for not handled docs.replace(SA("\\\\ref"),SA("")); // \b word -> word<\b> diff --git a/doc/formulas.doc b/doc/formulas.doc index 520f089..88a8725 100644 --- a/doc/formulas.doc +++ b/doc/formulas.doc @@ -100,9 +100,27 @@ the section should contain valid command for the specific environment. \warning Currently, doxygen is not very fault tolerant in recovering from typos in formulas. It may be necessary to remove the -files formula.repository that are written to the html and rtf directories to +files formula.repository that are written to the html, rtf etc. directories to get rid of an incorrect formula as well as the form_* files. +To have the possibility to define your own \LaTeX commands, for e.g. formula building blocks +or consistent writing of certain words, the configuration option \ref cfg_formula_macrofile "FORMULA_MACROFILE" +can be used. to supply a file with \LaTeX commands. +This file can contain \LaTeX `\newcommand` and \`renewcommand` commands and they are included +formulas (image version and MathJax version) as well as in the generated \LaTeX output (for PDF generation).
+The `\newcommand` (and `\renewcommand`) are restricted to a version without optional +parameters so only the following types are supported: +``` +\newcommand{\cmd}{replacement} + and +\newcommand{\cmd}[nr]{replacement} +``` +e.g. +``` +\newcommand{\E}{\mathrm{E}} +\newcommand{\ccSum}[3]{\sum_{#1}^{#2}{#3}} +``` + \htmlonly Go to the next section or return to the index. diff --git a/src/config.xml b/src/config.xml index e68b3d7..a226863 100644 --- a/src/config.xml +++ b/src/config.xml @@ -2377,6 +2377,16 @@ The \c DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. ]]> +