From b95b4766c7107e9b3ff0969534fe54c131412249 Mon Sep 17 00:00:00 2001 From: albert-github Date: Tue, 20 Apr 2021 14:28:19 +0200 Subject: Problems with some commands in MathJax Especially with commands like `\f$\mbox{\LaTeX}\f$`MathJax has some problem as it is not, yet, able to use the commands `\raise` and `lower` inside the `\mbox` as used in this LaTeX command. Also switching in and out of math-mode doesn't work as the resulting code either doesn't work in MathJax or in LaTeX, hence the new command s `\f(` and `\f)`. --- doc/Doxyfile | 4 ++-- doc/commands.doc | 19 +++++++++++++++++++ doc/formulas.doc | 29 +++++++++++++++++++++-------- src/commentcnv.l | 8 ++++++-- src/commentscan.l | 20 +++++++++++++++----- src/docparser.h | 2 +- src/htmldocvisitor.cpp | 5 +++++ src/lexcode.l | 4 ++-- src/lexscanner.l | 4 ++-- src/markdown.cpp | 5 +++++ src/pre.l | 4 ++-- src/scanner.l | 12 ++++++++---- 12 files changed, 88 insertions(+), 28 deletions(-) diff --git a/doc/Doxyfile b/doc/Doxyfile index caf6229..15d210e 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -51,8 +51,8 @@ USE_PDFLATEX = YES STRIP_CODE_COMMENTS = NO HTML_STYLESHEET = doxygen_manual.css HTML_EXTRA_FILES = doxygen_logo.svg -ALIASES = LaTeX="\f$\mbox{\LaTeX}\f$" -ALIASES += TeX="\f$\mbox{\TeX}\f$" +ALIASES = LaTeX="\f(\LaTeX\f)" +ALIASES += TeX="\f(\TeX\f)" ALIASES += forceNewPage="\latexonly \newpage \endlatexonly" LATEX_BATCHMODE = YES LATEX_EXTRA_STYLESHEET = manual.sty diff --git a/doc/commands.doc b/doc/commands.doc index eff2f42..ffab530 100644 --- a/doc/commands.doc +++ b/doc/commands.doc @@ -104,6 +104,8 @@ documentation: \refitem cmdexample \\example \refitem cmdexception \\exception \refitem cmdextends \\extends +\refitem cmdfrndopen \\f( +\refitem cmdfrndclose \\f) \refitem cmdfdollar \\f\$ \refitem cmdfbropen \\f[ \refitem cmdfbrclose \\f] @@ -3191,6 +3193,23 @@ class Receiver \sa section \ref formulas "formulas" for an example.
+\section cmdfrndopen \\f( + + \addindex \\f( + + Marks the start of an in-text formula, but contrary to \ref cmdfdollar "\\f$" it will + not explicitly open the math-mode in \LaTeX. + \sa section \ref cmdfrndclose "\\f)" and section \ref formulas "formulas". + +
+\section cmdfrndclose \\f) + + \addindex \\f) + + Marks the end of an in-text formula started with \ref cmdfrndopen "\\f(". + \sa section \ref cmdfrndopen "\\f(" and section \ref formulas "formulas". + +
\section cmdfbropen \\f[ \addindex \\f[ diff --git a/doc/formulas.doc b/doc/formulas.doc index e9a8076..1a87977 100644 --- a/doc/formulas.doc +++ b/doc/formulas.doc @@ -34,10 +34,10 @@ require the above tools. If you enable \ref cfg_use_mathjax "USE_MATHJAX" in the configuration then the latex formulas will be copied to the HTML "as is" and a client side javascript will parse them and turn them into (interactive) images. -There are three ways to include formulas in the documentation. +There are four ways to include formulas in the documentation.
  1. Using in-text formulas that appear in the running text. - These formulas should be put between a pair of \\f\$ + These formulas should be put between a pair of \ref cmdfdollar "\\f\$" commands, so \verbatim The distance between \f$(x_1,y_1)\f$ and \f$(x_2,y_2)\f$ is @@ -47,8 +47,19 @@ There are three ways to include formulas in the documentation. The distance between \f$(x_1,y_1)\f$ and \f$(x_2,y_2)\f$ is \f$\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}\f$.
    +
  2. Using in-text formulas that appear in the running text, contrary to + \ref cmdfdollar "\\f$" it will not explicitly open the math mode in \LaTeX. + These formulas should be put between \ref cmdfrndclose "\\f(" and + \ref cmdfrndopen "\\f)" commands, so +\verbatim + The LaTeX and Tex logos are: \f(\LaTeX \f) and \f(\TeX \f). +\endverbatim results in: + + The LaTeX and Tex logos are: \f(\LaTeX \f) and \f(\TeX \f). +
  3. Unnumbered displayed formulas that are centered on a separate line. - These formulas should be put between \\f[ and \\f] commands. + These formulas should be put between \ref cmdfbropen "\\f[" and + \ref cmdfbrclose "\\f]" commands. An example: \verbatim \f[ @@ -74,9 +85,9 @@ There are three ways to include formulas in the documentation. \right| \f]
  4. Formulas or other latex elements that are not in a math - environment can be specified using \\f{environment}, where + environment can be specified using \ref cmdfcurlyopen "\\f{environment}", where \c environment is the name of the \LaTeX environment, - the corresponding end command is \\f}. Here is an example for an + the corresponding end command is \ref cmdfcurlyclose "\\f}". Here is an example for an equation array \verbatim \f{eqnarray*}{ @@ -94,9 +105,11 @@ There are three ways to include formulas in the documentation. &=& 9.82066032\,\mbox{m/s}^2 \f}
-For the first two commands one should make sure formulas contain -valid commands in \LaTeX's math-mode. For the third command -the section should contain valid command for the specific environment. +For the first and third commands one should make sure formulas contain +valid commands in \LaTeX's math-mode. +The second command should valid text-mode commands that also work in math-mode when using +\ref cfg_use_mathjax "USE_MATHJAX". +For the fourth command 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 diff --git a/src/commentcnv.l b/src/commentcnv.l index 2d0a4aa..bf2a6fe 100644 --- a/src/commentcnv.l +++ b/src/commentcnv.l @@ -438,7 +438,7 @@ SLASHopt [/]* } BEGIN(VerbatimCode); } -[\\@]("f$"|"f["|"f{") { +[\\@]("f$"|"f["|"f{"|"f(") { copyToOutput(yyscanner,yytext,(int)yyleng); yyextra->blockName=&yytext[1]; if (yyextra->blockName.at(1)=='[') @@ -449,6 +449,10 @@ SLASHopt [/]* { yyextra->blockName.at(1)='}'; } + else if (yyextra->blockName.at(1)=='(') + { + yyextra->blockName.at(1)=')'; + } yyextra->lastCommentContext = YY_START; BEGIN(Verbatim); } @@ -467,7 +471,7 @@ SLASHopt [/]* . { /* any other character */ copyToOutput(yyscanner,yytext,(int)yyleng); } -[\\@]("endverbatim"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endrtfonly"|"endmanonly"|"f$"|"f]"|"f}") { /* end of verbatim block */ +[\\@]("endverbatim"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endrtfonly"|"endmanonly"|"f$"|"f]"|"f}"|"f)") { /* end of verbatim block */ copyToOutput(yyscanner,yytext,(int)yyleng); if (&yytext[1]==yyextra->blockName) // end of formula { diff --git a/src/commentscan.l b/src/commentscan.l index dc16d4c..d55fdab 100644 --- a/src/commentscan.l +++ b/src/commentscan.l @@ -540,6 +540,7 @@ STopt [^\n@\\]* %x InheritParam %x ExtendsParam %x ReadFormulaShort +%x ReadFormulaRound %x ReadFormulaLong %x AnchorLabel %x HtmlComment @@ -555,7 +556,7 @@ STopt [^\n@\\]* /* What can happen in while parsing a comment block: * commands (e.g. @page, or \page) * escaped commands (e.g. @@page or \\page). - * formulas (e.g. \f$...\f$ \f[...\f] \f{...\f}) + * formulas (e.g. \f$...\f$ \f[...\f] \f{...\f} \f(...\f) ) * directories (e.g. \doxygen\src\) * autolist end. (e.g. a dot on an otherwise empty line) * newlines. @@ -753,6 +754,11 @@ STopt [^\n@\\]* yyextra->formulaNewLines=0; BEGIN(ReadFormulaShort); } +{B}*{CMD}"f(" { // start of a inline formula + yyextra->formulaText=""; + yyextra->formulaNewLines=0; + BEGIN(ReadFormulaRound); + } {B}*{CMD}"f[" { // start of a block formula setOutput(yyscanner,OutputDoc); yyextra->formulaText="\\["; @@ -936,6 +942,10 @@ STopt [^\n@\\]* addOutput(yyscanner," "+addFormula(yyscanner)); BEGIN(Comment); } +{CMD}"f)" { // end of inline formula + addOutput(yyscanner," "+addFormula(yyscanner)); + BEGIN(Comment); + } {CMD}"f]" { // end of block formula yyextra->formulaText+="\\]"; addOutput(yyscanner," "+addFormula(yyscanner)); @@ -947,15 +957,15 @@ STopt [^\n@\\]* addOutput(yyscanner," "+addFormula(yyscanner)); BEGIN(Comment); } -[^\\@\n]+ { // any non-special character +[^\\@\n]+ { // any non-special character yyextra->formulaText+=yytext; } -\n { // new line +\n { // new line yyextra->formulaNewLines++; yyextra->formulaText+=*yytext; yyextra->lineNr++; } -. { // any other character +. { // any other character yyextra->formulaText+=*yytext; } @@ -3235,7 +3245,7 @@ static yy_size_t yyread(yyscan_t yyscanner,char *buf,yy_size_t max_size) static void checkFormula(yyscan_t yyscanner) { struct yyguts_t *yyg = (struct yyguts_t*)yyscanner; - if (YY_START==ReadFormulaShort || YY_START==ReadFormulaLong) + if (YY_START==ReadFormulaShort || YY_START==ReadFormulaRound || YY_START==ReadFormulaLong) { warn(yyextra->fileName,yyextra->lineNr,"End of comment block while inside formula."); } diff --git a/src/docparser.h b/src/docparser.h index a510b32..9078f6b 100644 --- a/src/docparser.h +++ b/src/docparser.h @@ -634,7 +634,7 @@ class DocFormula : public DocNode QCString relPath() const { return m_relPath; } int id() const { return m_id; } void accept(DocVisitor *v) { v->visit(this); } - bool isInline() { return m_text.length()>0 ? m_text.at(0)!='\\' : TRUE; } + bool isInline() { return m_text.length()>1 ? !(m_text.at(0)=='\\' && (m_text.at(1)=='{' || m_text.at(1)=='[')): TRUE; } private: QCString m_name; diff --git a/src/htmldocvisitor.cpp b/src/htmldocvisitor.cpp index 545b96e..6f11d21 100644 --- a/src/htmldocvisitor.cpp +++ b/src/htmldocvisitor.cpp @@ -853,6 +853,11 @@ void HtmlDocVisitor::visit(DocFormula *f) text = text.mid(1,text.length()-2); m_t << "\\("; } + else if (!bDisplay && !text.isEmpty()) + { + closeInline=TRUE; + m_t << "\\("; + } m_t << convertToHtml(text); if (closeInline) { diff --git a/src/lexcode.l b/src/lexcode.l index a118703..9d4c9ba 100644 --- a/src/lexcode.l +++ b/src/lexcode.l @@ -699,7 +699,7 @@ NONLopt [^\n]* ({CMD}{CMD}){ID}/[^a-z_A-Z0-9] { // escaped command yyextra->CCodeBuffer += yytext; } -{CMD}("f$"|"f["|"f{") { +{CMD}("f$"|"f["|"f{"|"f(") { yyextra->CCodeBuffer += yytext; yyextra->docBlockName=&yytext[1]; if (yyextra->docBlockName.at(1)=='{') @@ -769,7 +769,7 @@ NONLopt [^\n]* BEGIN(DocBlock); } } -[\\@]("f$"|"f]"|"f}") { +[\\@]("f$"|"f]"|"f}"|"f)") { yyextra->CCodeBuffer += yytext; BEGIN(DocBlock); } diff --git a/src/lexscanner.l b/src/lexscanner.l index f148e16..0422b1b 100644 --- a/src/lexscanner.l +++ b/src/lexscanner.l @@ -646,7 +646,7 @@ NONLopt [^\n]* ({CMD}{CMD}){ID}/[^a-z_A-Z0-9] { // escaped command yyextra->CCodeBuffer += yytext; } -{CMD}("f$"|"f["|"f{") { +{CMD}("f$"|"f["|"f{"|"f(") { yyextra->CCodeBuffer += yytext; yyextra->docBlockName=&yytext[1]; if (yyextra->docBlockName.at(1)=='{') @@ -715,7 +715,7 @@ NONLopt [^\n]* BEGIN(DocBlock); } } -[\\@]("f$"|"f]"|"f}") { +[\\@]("f$"|"f]"|"f}"|"f)") { yyextra->CCodeBuffer += yytext; BEGIN(DocBlock); } diff --git a/src/markdown.cpp b/src/markdown.cpp index 3de454b..5f2b8f6 100644 --- a/src/markdown.cpp +++ b/src/markdown.cpp @@ -305,6 +305,7 @@ static Alignment markersToAlignment(bool leftMarker,bool rightMarker) // \code .. \endcode // \msc .. \endmsc // \f$..\f$ +// \f(..\f) // \f[..\f] // \f{..\f} // \verbatim..\endverbatim @@ -353,6 +354,10 @@ QCString Markdown::isBlockCommand(const char *data,int offset,int size) { return "f$"; } + else if (data[end]=='(') + { + return "f)"; + } else if (data[end]=='[') { return "f]"; diff --git a/src/pre.l b/src/pre.l index 6c46f39..75b2380 100644 --- a/src/pre.l +++ b/src/pre.l @@ -1163,7 +1163,7 @@ WSopt [ \t\r]* outputChar(yyscanner,'/');outputChar(yyscanner,'*'); //yyextra->commentCount++; } -[\\@][\\@]("f{"|"f$"|"f[") { +[\\@][\\@]("f{"|"f$"|"f[""f(") { outputArray(yyscanner,yytext,(int)yyleng); } ^({B}*"*"+)?{B}{0,3}"~~~"[~]* { @@ -1315,7 +1315,7 @@ WSopt [ \t\r]* BEGIN(yyextra->condCtx); } } -[\\@]("endverbatim"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endrtfonly"|"endmanonly"|"enddot"|"endcode"|"f$"|"f]"|"f}") { /* end of verbatim block */ +[\\@]("endverbatim"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endrtfonly"|"endmanonly"|"enddot"|"endcode"|"f$"|"f]"|"f}""f}") { /* end of verbatim block */ outputArray(yyscanner,yytext,(int)yyleng); if (yytext[1]=='f' && yyextra->blockName=="f") { diff --git a/src/scanner.l b/src/scanner.l index a37ff09..bfb91e2 100644 --- a/src/scanner.l +++ b/src/scanner.l @@ -4521,7 +4521,7 @@ NONLopt [^\n]* yyextra->fullArgString+=yytext; BEGIN(CopyArgVerbatim); } -{CMD}("f$"|"f["|"f{") { +{CMD}("f$"|"f["|"f{"|"f(") { yyextra->docBlockName=&yytext[1]; if (yyextra->docBlockName.at(1)=='[') { @@ -4531,10 +4531,14 @@ NONLopt [^\n]* { yyextra->docBlockName.at(1)='}'; } + if (yyextra->docBlockName.at(1)=='(') + { + yyextra->docBlockName.at(1)=')'; + } yyextra->fullArgString+=yytext; BEGIN(CopyArgVerbatim); } -[\\@]("endverbatim"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endmanonly"|"endrtfonly"|"enddot"|"endcode"|"f$"|"f]"|"f}")/[^a-z_A-Z0-9\-] { // end of verbatim block +[\\@]("endverbatim"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endmanonly"|"endrtfonly"|"enddot"|"endcode"|"f$"|"f]"|"f}"|"f)")/[^a-z_A-Z0-9\-] { // end of verbatim block yyextra->fullArgString+=yytext; if (yytext[1]=='f') // end of formula { @@ -6531,7 +6535,7 @@ NONLopt [^\n]* ({CMD}{CMD}){ID}/[^a-z_A-Z0-9] { // escaped command yyextra->docBlock << yytext; } -{CMD}("f$"|"f["|"f{") { +{CMD}("f$"|"f["|"f{"|"f(") { yyextra->docBlock << yytext; yyextra->docBlockName=&yytext[1]; if (yyextra->docBlockName.at(1)=='{') @@ -6613,7 +6617,7 @@ NONLopt [^\n]* BEGIN(DocBlock); } } -[\\@]("f$"|"f]"|"f}") { +[\\@]("f$"|"f]"|"f}"|"f)") { yyextra->docBlock << yytext; BEGIN(DocBlock); } -- cgit v0.12