diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/lwarp/lwarp.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/lwarp/lwarp.sty | 499 |
1 files changed, 345 insertions, 154 deletions
diff --git a/Master/texmf-dist/tex/latex/lwarp/lwarp.sty b/Master/texmf-dist/tex/latex/lwarp/lwarp.sty index fc765c159b5..a204cb86a25 100644 --- a/Master/texmf-dist/tex/latex/lwarp/lwarp.sty +++ b/Master/texmf-dist/tex/latex/lwarp/lwarp.sty @@ -17,7 +17,7 @@ %% version 2005/12/01 or later. \NeedsTeXFormat{LaTeX2e}[1999/12/01] \ProvidesPackage{lwarp} - [2020/05/01 v0.85 Allows LaTeX to directly produce HTML5 output.] + [2020/05/12 v0.86 Allows LaTeX to directly produce HTML5 output.] @@ -4182,114 +4182,259 @@ page_compositor "." \end{LWRwriteconf} + \begin{LWRwriteconf} \begin{filecontents*}[overwrite]{lwarp_mathjax.txt} -<!-- https://groups.google.com/forum/#!topic/ - mathjax-users/jUtewUcE2bY --> -<script type="text/x-mathjax-config"> -MathJax.Hub.Register.StartupHook("TeX AMSmath Ready",function () { - var seteqsectionDefault = {name: "", num: 0}; - var seteqsections = {}, seteqsection = seteqsectionDefault; - var TEX = MathJax.InputJax.TeX, PARSE = TEX.Parse; - var AMS = MathJax.Extension["TeX/AMSmath"]; - TEX.Definitions.Add({ - macros: { - seteqsection: "mySection", - seteqnumber: "mySetEqNumber" - } - }); - - PARSE.Augment({ - mySection: function (name) { - seteqsection.num = AMS.number; - var n = this.GetArgument(name); - if (n === "") { - seteqsection = seteqsectionDefault; - } else { - if (!seteqsections["_"+n]) - seteqsections["_"+n] = {name:n, num:0}; - seteqsection = seteqsections["_"+n]; +<script> +// Lwarp MathJax emulation code +// Based on code by Davide P. Cervone. +// Original code: https://github.com/mathjax/MathJax/issues/2313 +// Modified by Brian Dunn to adjust equation numbering, add subequations, +// and add starred macros. +// Equation numbering: https://github.com/mathjax/MathJax/issues/2427 +// Starred macros: https://github.com/mathjax/MathJax/issues/2428 +// +// LaTeX can use \seteqnumber{subequations?}{section}{number} before each equation. +// subequations? is 0 usually, 1 if inside subequations. +// section is a string printed as-is, or empty. +// number is auto-incremented by MathJax between equations. +// +MathJax = { + subequations: "0", + section: "", + loader: { + load: ['[tex]/tagFormat'] + }, + startup: { + ready() { + // + // These would be replaced by import commands if you wanted to make + // a proper extension. + // + const Configuration = MathJax._.input.tex.Configuration.Configuration; + const CommandMap = MathJax._.input.tex.SymbolMap.CommandMap; + const Macro = MathJax._.input.tex.Symbol.Macro; + const TexError = MathJax._.input.tex.TexError.default; + const ParseUtil = MathJax._.input.tex.ParseUtil.default; + const expandable = MathJax._.util.Options.expandable; + + // + // These are the names of the command maps: + // + const SETEQNUMBERMAP = 'seteqnumberCoreMap' ; + + // + // These functions implement the macros: + // + const seteqnumberFunction = (parser, name) => { + // Get the macro parameters + const star = parser.GetStar(); // true if there is a * + const optBrackets = parser.GetBrackets(name); // contents of optional brackets + const newsubequations = parser.GetArgument(name); // the subequations argument + const neweqsection = parser.GetArgument(name); // the eq section argument + const neweqnumber = parser.GetArgument(name); // the eq number argument + MathJax.config.subequations=newsubequations ; // a string with boolean meaning + MathJax.config.section=neweqsection ; // a string with numeric meaning + parser.tags.counter = parser.tags.allCounter = neweqnumber ; + }; + + // + // This is the configuration for the seteqnumberFunctionConfig TeX extension. + // + const seteqnumberFunctionConfig = Configuration.create('seteqnumberCore', { + // + // Initialize the extension by creating the command map, + // then append the command map to the given configuration as a macro handler. + // + init(config) { + const map = new CommandMap(SETEQNUMBERMAP,{},{}); + config.append( + Configuration.create( + 'seteqnumberDefs', + {handler: {macro: [SETEQNUMBERMAP]}} + ) + ); + }, + + // + // Add options (from the + // seteqnumberCore configuration object in the document's + // option list, if any). + // + config(config, jax) { + const map = jax.parseOptions.handlers.retrieve(SETEQNUMBERMAP); + const options = jax.parseOptions.options.seteqnumberCore; + for (const cs of Object.keys(options)) { + map.add(cs, new Macro(cs, seteqnumberFunction, options[cs])); + } + }, + + options: { + seteqnumberCore: expandable({}) } - AMS.number = seteqsection.num; - }, - mySetEqNumber: function (name) { - var n = this.GetArgument(name); - if (!n || !n.match(/^ *[0-9]+ *$/)) - n = ""; - else - n = parseInt(n)-1; - <!-- $ syntax highlighting --> - if (n === "" || n < 1) - TEX.Error - ("Argument to "+name+" should be a positive integer"); - AMS.number = n; - } - }); - MathJax.Hub.Config({ - TeX: { - equationNumbers: { - formatTag: function (n) { - <!-- if not numeric, don't include the chapter --> - if (!n.match(/^ *[0-9]+ *$/ )) - <!-- $ syntax highlighting --> - return "("+(n).replace(/^\./,"")+")" ; - else - return "("+(seteqsection.name+"."+n).replace(/^\./,"")+")" ; - }, - formatID: function (n) { - n = (seteqsection.name+'.'+n).replace - (/[:"'<>&]/g,"").replace(/^\./,""); - return 'mjx-eqn-' + n; + } + ); + + const IFSTARMAP = 'ifstarMap'; + + // + // This function implements an ifstar macro. + // + const IfstarFunction = (parser, name, resultstar, resultnostar) => { + // + // Get the macro parameters + // + const star = parser.GetStar(); // true if there is a * + // + // Construct the replacement string for the macro + // + const macro = [(star ? resultstar : resultnostar)].join(''); + // + // Insert the replacement string into the TeX string, and check + // that there haven't been too many maxro substitutions (prevents + // infinite loops). + // + parser.string = ParseUtil.addArgs(parser, macro, parser.string.slice(parser.i)); + parser.i = 0; + if (++parser.macroCount > parser.configuration.options.maxMacros) { + throw new TexError('MaxMacroSub1', + 'MathJax maximum macro substitution count exceeded; ' + + 'is there a recursive macro call?'); + } + }; + + // + // This is the configuration for the IfstarConfiguration TeX extension. + // + const IfstarConfiguration = Configuration.create('Ifstar', { + // + // Initialize the extension by creating the command map for the + // macros defined by \DeclareIfstar, and add the + // \DeclareIfstar macro itself. Then append the + // command map to the given configuration as a macro handler + // + init(config) { + const map = new CommandMap(IFSTARMAP, { + DeclareIfstar: ['Declare_Ifstar'] + }, { + // + // Implements \DeclareIfstar control sequence. + // + Declare_Ifstar(parser, name) { + // + // Get the control sequence to define and the starred and + // non-starred macros to use. + // + let cs = ParseUtil.trimSpaces(parser.GetArgument(name)); + const resultstar = parser.GetArgument(name); + const resultnostar = parser.GetArgument(name); + // + // Check that the control sequence name is valid + // + if (cs.charAt(0) === '\\') cs = cs.substr(1); + if (!cs.match(/^(.|[a-z]+)$/i)) { //$ syntax highlighting + throw new TexError( + 'IllegalControlSequenceName', + 'Illegal control sequence name for %1', + name + ); + } + // + // Look up the command map and add the new macro to it using + // IfstarFunction as the function and passing it the + // given starred and non-starred macros. + // + const map = parser.configuration.handlers.retrieve(IFSTARMAP); + map.add(cs, new Macro(cs, IfstarFunction, [resultstar, resultnostar])); } + }); + config.append( + Configuration.create('IfstarDefs', {handler: {macro: [IFSTARMAP]}}) + ); + }, + + // + // Add any user-defined starred/non-starred macros (from the + // Ifstar configuration object in the document's + // option list), if any. + // + config(config, jax) { + const map = jax.parseOptions.handlers.retrieve(IFSTARMAP); + const starmacros = jax.parseOptions.options.Ifstar; + for (const cs of Object.keys(starmacros)) { + map.add(cs, new Macro(cs, IfstarFunction, starmacros[cs])); + } + }, + + // + // Indicate that Ifstar is a valid option, and can have + // any number of definitions. The format is + // + // name: [starred, non-starred] + // + // where 'name' is the macro name, and starred and non-starred are the + // macros to use for the \name macro. You can include + // pre-defined macros here, which will be available without + // further configuration. + // + options: { + Ifstar: expandable({}) } - } - }); -}); -</script> + }); -<!-- http://docs.mathjax.org/en/latest/options/ThirdParty.html --> -<script type="text/x-mathjax-config"> - MathJax.Ajax.config.path["Contrib"] = - "https://cdn.mathjax.org/mathjax/contrib"; -</script> + MathJax.startup.defaultReady(); -<script type="text/x-mathjax-config"> -MathJax.Hub.Config({ - TeX: { - extensions: ["autoload-all.js"] , - equationNumbers: { - autoNumber: "AMS" + // For forward references: + MathJax.startup.input[0].preFilters.add(({math}) => { + if (math.inputData.recompile){ + MathJax.config.subequations = math.inputData.recompile.subequations; + MathJax.config.section = math.inputData.recompile.section; } - } -}); -</script> - -<!-- Alternative CDN provider: --> -<script type="text/javascript" async -src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js?config=TeX-AMS_HTML-full"> + }); + MathJax.startup.input[0].postFilters.add(({math}) => { + if (math.inputData.recompile){ + math.inputData.recompile.subequations = MathJax.config.subequations; + math.inputData.recompile.section = MathJax.config.section; + } + }); + } // ready + }, // startup + + tex: { + packages: {'[+]': ['seteqnumberCore', 'tagFormat', 'Ifstar']}, + seteqnumberCore: { + seteqnumber: [] // a user-defined macro + }, + tags: "ams", + tagFormat: { + number: function (n) { + if(MathJax.config.subequations==0) + return(MathJax.config.section + n); + else + return(MathJax.config.section + String.fromCharCode(96+n)); + }, + }, + } +} </script> -<!-- No longer supported after April 30, 2017: --> -<!-- <script - src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML-full"> -</script> ---> - + id="MathJax-script" + src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js" +></script> \end{filecontents*} \end{LWRwriteconf} - \begin{LWRcreatelwarpmk} \begin{filecontents*}[overwrite]{lwarpmk.lua} #!/usr/bin/env texlua -- Copyright 2016-2020 Brian Dunn -printversion = "v0.85" +printversion = "v0.86" requiredconfversion = "2" -- also at *lwarpmk.conf function printhelp () @@ -6527,11 +6672,14 @@ end -- not --version \LWR@traceinfo{LWR@filenamenoblanks edef: !\LWR@thisnewfilename!}% \fullexpandarg% \LWR@simplifyname*{ } +\LWR@simplifyname*{*} +\LWR@simplifyname*{(} +\LWR@simplifyname*{)} +\LWR@simplifyname*{.} \LWR@simplifyname*{!} \LWR@simplifyname*{,} \LWR@simplifyname*{'} \LWR@simplifyname*{+} -\LWR@simplifyname*{,} \LWR@simplifyname*{/} \LWR@simplifyname*{:} \LWR@simplifyname*{;} @@ -6769,6 +6917,7 @@ end -- not --version \LWR@customizedMathJax \LWR@startpars \end{BlockClass} +\typeout{Done.} \typeout{---} \LWR@startpars @@ -7340,7 +7489,17 @@ end -- not --version \begingroup% \LWR@restoreoriglists% \boolfalse{LWR@verbtags}% - \verbatiminput{\LWR@mathjaxfilename}% + \IfFileExists{\LWR@mathjaxfilename}% + {\verbatiminput{\LWR@mathjaxfilename}}% + {% + \PackageError{lwarp}% + {% + \protect\MathJaxFilename\space specified the file\MessageBreak + \space\space\LWR@mathjaxfilename\MessageBreak + which does not exist% + }% + {Specify an existing file, or remove \protect\MathJaxFilename.}% + }% \booltrue{LWR@verbtags}% \endgroup% \LWR@stoppars% @@ -7383,8 +7542,6 @@ end -- not --version \setlength{\abovecaptionskip}{0ex} \renewcommand{\ps@plain}{} \let\LWR@origcaption\caption -\let\LWR@origltx@label\ltx@label -\let\ltx@label\LWR@htmlmathlabel \global\boolfalse{LWR@doingapar} \global\boolfalse{LWR@doingstartpars} \mainmatter @@ -9905,30 +10062,53 @@ end -- not --version } +\newcommand*{\LWR@label@subcreatetag}{% + \LWR@htmltag{a \LWR@print@mbox{id="\LWR@sanitized"}}% + \LWR@htmltag{/a}% +} + +\newcommand*{\LWR@label@inmathcomment}{% + \ifboolexpr{bool{mathjax} or ( bool{FormatWP} and bool{WPMarkMath} ) }% + {% + \mbox{% + \ifdef{\totwidth@}{\ifbool{LWR@amsmultline}{}{\hspace*{\totwidth@}}}{}% + \LWR@htmlclosecomment% + \LWR@label@subcreatetag% + \LWR@htmlopencomment% + }% mbox + }% mathjax + {% + \LWR@label@subcreatetag% + }% +} + \newcommand*{\LWR@label@createtag}[1]{% \LWR@traceinfo{LWR@label@createtag !#1!}% \ifnumcomp{\value{LWR@lateximagedepth}}{>}{0}% {}% {% not lateximage \LWR@sanitize{#1}% - \ifbool{LWR@doingstartpars}% - {% pars allowed - \ifbool{LWR@doingapar}% - {% par started - \LWR@htmltag{a \LWR@print@mbox{id="\LWR@sanitized"}}% - \LWR@htmltag{/a}% - }% par started - {% par not started - \LWR@stoppars% - \LWR@htmltag{a \LWR@print@mbox{id="\LWR@sanitized"}}% - \LWR@htmltag{/a}% - \LWR@startpars% - }% par not started - }% pars allowed - {% pars not allowed - \LWR@htmltag{a \LWR@print@mbox{id="\LWR@sanitized"}}% - \LWR@htmltag{/a}% - }% pars not allowed + \ifbool{LWR@insidemathcomment}% + {% inside HTML math comment + \LWR@label@inmathcomment% + }% inside HTML math comment + {% not inside HTML math comment + \ifbool{LWR@doingstartpars}% + {% pars allowed + \ifbool{LWR@doingapar}% + {% par started + \LWR@label@subcreatetag% + }% par started + {% par not started + \LWR@stoppars% + \LWR@label@subcreatetag% + \LWR@startpars% + }% par not started + }% pars allowed + {% pars not allowed + \LWR@label@subcreatetag% + }% pars not allowed + }% not inside HTML math comment }% not lateximage } \NewDocumentCommand{\LWR@new@label}{m}{% @@ -9977,7 +10157,7 @@ end -- not --version {% \ifthenelse{\cnttest{\LWR@lateximagedepthref{#1}}{>}{0}}% {% - \LWR@ImagesName\LWR@lateximagenumberref{#1}% + lateximage-\BaseJobname-\LWR@lateximagenumberref{#1}% }% {% \LWR@traceinfo{LWR@startref D3}% @@ -10088,7 +10268,7 @@ end -- not --version \LWR@subhyperreftext% } -\newrobustcmd*{\href}{% +\newrobustcmd*{\LWR@href}{% \begingroup% \LWR@linkcatcodes% \LWR@hrefb% @@ -10102,7 +10282,7 @@ end -- not --version \endgroup% } -\newrobustcmd*{\nolinkurl}{% +\newrobustcmd*{\LWR@nolinkurl}{% \begingroup% \LWR@linkcatcodes% \LWR@nolinkurlb% @@ -10112,11 +10292,11 @@ end -- not --version \LWR@ensuredoingapar% \def\LWR@templink{#1}% \@onelevel@sanitize\LWR@templink% - \href{\LWR@templink}{\LWR@templink}% + \LWR@href{\LWR@templink}{\LWR@templink}% \endgroup% } -\newrobustcmd*{\url}{% +\newrobustcmd*{\LWR@url}{% \begingroup% \LWR@linkcatcodes% \LWR@urlb% @@ -10974,6 +11154,9 @@ end -- not --version \newbool{LWR@indisplaymathimage} +\newbool{LWR@insidemathcomment} +\boolfalse{LWR@insidemathcomment} + \newbool{LWR@xfakebold} \boolfalse{LWR@xfakebold} @@ -11384,29 +11567,53 @@ end -- not --version } \newcounter{LWR@nextequation} -\newcommand*{\LWR@syncmathjax}{% - \ifcsdef{thechapter}{ - \LWR@stoppars% - \InlineClass{hidden}{ - \textbackslash( - \textbackslash{}seteqsection \{\thechapter\} - \textbackslash) +\newcommand\LWR@article@theequation{\@arabic\c@equation} + +\newcommand\LWR@book@theequation + {\ifnum \c@chapter>\z@ \thechapter.\fi \@arabic\c@equation} + +\newcommand\LWR@chapter@theequation{\thechapter.\arabic{equation}} +\newcommand\LWR@section@thequation{\thesection.\arabic{equation}} +\newcommand\LWR@subsection@thequation{\thesubsection.\arabic{equation}} + +\AtBeginDocument{ + % default per article class: + \newcommand*{\theMathJaxsubequations}{0} + \newcommand*{\theMathJaxsection}{} + \newcommand*{\theMathJaxequation}{\arabic{equation}} + + \ifdefstrequal{\theequation}{\LWR@article@theequation} + {}{ + \ifdefstrequal{\theequation}{\LWR@book@theequation}{ + \renewcommand*{\theMathJaxsection}{\ifnum \c@chapter>\z@ \thechapter.\fi} + }{ + \ifdefstrequal{\theequation}{\LWR@subsection@thequation}{ + \renewcommand*{\theMathJaxsection}{\thesubsection{}.} + }{ + \ifdefstrequal{\theequation}{\LWR@section@thequation}{ + \renewcommand*{\theMathJaxsection}{\thesection{}.} + }{ + \ifdefstrequal{\theequation}{\LWR@chapter@theequation}{ + \renewcommand*{\theMathJaxsection}{\thechapter{}.} + }{% unknown format + \PackageWarningNoLine{lwarp} + {% + Unknown equation tag format for \protect\theequation.\MessageBreak + Article-style equation numbering will be used% } - \LWR@startpars% - } - {}% not using chapters - \ifthenelse{\cnttest{\value{equation}}>0} - { - \setcounter{LWR@nextequation}{\value{equation}} - \addtocounter{LWR@nextequation}{1} + }}}}} +} +\newcommand*{\LWR@syncmathjax}{% \LWR@stoppars% \InlineClass{hidden}{ - \textbackslash( - \textbackslash{}seteqnumber \{\arabic{LWR@nextequation}\} - \textbackslash) + \textbackslash(% + \textbackslash{}seteqnumber% + \{\theMathJaxsubequations\}% + \{\theMathJaxsection\}% + \{\theMathJaxequation\}% + \textbackslash)% } \LWR@startpars% - }{}% not eq > 0 } \NewDocumentCommand{\LWR@hidelatexequation}{m +m}{% \LWR@stoppars @@ -11415,11 +11622,13 @@ end -- not --version \begingroup \@nameuse{LWR@orig#1} \LWR@restoreorigformatting + \booltrue{LWR@insidemathcomment} #2 \@nameuse{LWR@origend#1} \endgroup \LWR@htmlclosecomment + \boolfalse{LWR@insidemathcomment} \LWR@startpars } @@ -11576,22 +11785,6 @@ end -- not --version \newbool{LWR@amsmultline} \boolfalse{LWR@amsmultline} -\newcommand*{\LWR@htmlmathlabel}[1]{% - \LWR@traceinfo{LWR@htmlmathlabelb #1}% - \ifboolexpr{bool{mathjax} or ( bool{FormatWP} and bool{WPMarkMath} ) }% - {% - \text{% - \ifbool{LWR@amsmultline}{}{\hspace*{\totwidth@}}% - \LWR@htmlclosecomment% - \LWR@origltx@label{#1}% - \LWR@htmlopencomment% - }% text - }% mathjax - {% - \LWR@origltx@label{#1}% - }% -} - \newcommand*{\LWR@beginhideamsmath}{ \LWR@stoppars \LWR@origtilde\LWR@orignewline @@ -11599,12 +11792,14 @@ end -- not --version \begingroup \LWR@restoreorigformatting + \booltrue{LWR@insidemathcomment} } \newcommand*{\LWR@endhideamsmath}{ \endgroup \LWR@htmlclosecomment + \boolfalse{LWR@insidemathcomment} \LWR@orignewline \LWR@startpars } @@ -13193,8 +13388,7 @@ color:\LWR@origpound\LWR@tempcolor% \begin{warpHTML} -\newcounter{LWR@phantomsection} -\DeclareDocumentCommand{\phantomsection}{}{% +\newrobustcmd*{\LWR@phantomsection}{% \begingroup% \boolfalse{LWR@forcinghtmltoc}% \section*{}% @@ -13535,9 +13729,6 @@ color:\LWR@origpound\LWR@tempcolor% environments to force SVG output} \LWR@mathjaxwarn{jkmath}{} \LWR@mathjaxwarn{mathspec}{} - \LWR@mathjaxwarn{mathtools} - {Avoid starred macros.\MessageBreak - See the Lwarp manual for other limitations} \LWR@mathjaxwarn{multirow} {Multirow works as expected in text mode, but\MessageBreak limited emulation is provided for MathJax math.\MessageBreak @@ -13547,8 +13738,8 @@ color:\LWR@origpound\LWR@tempcolor% {Enclose its uses inside lateximage environments\MessageBreak to force SVG output} \LWR@mathjaxwarn{physics} - {The third-party extension is not yet used.\MessageBreak - Avoid starred macros and automatic delimiters.\MessageBreak + {The third-party extension is not used.\MessageBreak + Avoid automatic delimiters.\MessageBreak Use all mandatory arguments, adding empty as needed.\MessageBreak See the Lwarp manual for details} \LWR@mathjaxwarn{unicode-math} |