TransWikia.com

Overleaf Moodle not accepting $ dollar sign

TeX - LaTeX Asked on April 1, 2021

I’m trying to compile my LaTeX with usepackage{moodle} on Overleaf.

Whenever I want to include the dollar sign $, it won’t compile correctly.

What’s the correct way to include a dollar sign in the document so that LaTeX will compile correctly?

documentclass{article} 
usepackage{moodle}
begin{document}
begin{quiz}{test}
begin{multi}{Word Problem}
A store charges $$ 1$ for packaging an item. Alice wants to package 10 items. How much does she need to pay the store for packaging the 10 items separately.
item $5$
item $6$
item $8$
item* $10$
end{multi}
end{quiz}
end{document}`

With $ in front of "1" it will compile with an error. If you remove $ everything is fine.

To be precise, here are the error messages:

Compile Error. Sorry, your LaTeX code couldn't compile for some reason. 
Please check the errors below for details, or view the raw log.
nnn.tex

Runaway argument?

for packaging an item. Alice wants to package 10 items. How much doeETC.
! File ended while scanning use of htmlize@inlinemathshift@replace.
<inserted text> 
            par 
<*> nnn.tex
       
I suspect you have forgotten a `}', causing me
to read past where you wanted me to stop.
I'll try to recover; but if the error is serious,
you'd better type `E' or `X' now and fix your file.

nnn.tex
Emergency stop.

<*> nnn.tex
       
*** (job aborted, no legal end found)


 Here is how much of TeX's memory you used:
 3655 strings out of 480906
 62407 string characters out of 5908280
 315048 words of memory out of 5000000
 19216 multiletter control sequences out of 15000+600000
 538169 words of font info for 42 fonts, out of 8000000 for 9000
 1141 hyphenation exceptions out of 8191
 50i,6n,56p,849b,376s stack positions out of 5000i,500n,10000p,200000b,80000s
 !  ==> Fatal error occurred, no output PDF file produced!

One Answer

The moodle package has to perform conversion of TeX material to HTML. In particular, it attempts to grab the contents of inline math environments ($...$). When finding the left delimiter (first $), the strategy adopted by the package (as of version 0.5) is to blindly look for the next dollar sign. While this works in most cases, your example shows that the $ character used in such environments fools moodle.

There are (at least) two workarounds to this problem:

  1. If possible, avoid the use of the dollar sign inside inline math environments (see @egreg's comment). The package moodle will not be fooled by $$1$.
  2. Use LaTeX's inline math delimiters (...). The package moodle will not be fooled by ($1).

If none of these workarounds is an option, you can fix moodle's internal commands by adding the following code to your preamble.

makeatletter
longdefhtmlize@inlinemath@recursive@i#1#2#3htmlize@rdelim@i{%
  deftest@i{#1}%
  ifxtest@i@otherbackslash
    g@addto@macromathtext{#1#2}%
    defhtmlize@next@i{xahtmlize@inlinemath@recursive@i#3htmlize@rdelim@i}%
  else
    ifxtest@i@otherdollar
      lethtmlize@next@i=relax
      g@addto@macroaftertext{#2#3}%
    else
      g@addto@macromathtext{#1}%
      defhtmlize@next@i{xahtmlize@inlinemath@recursive@i#2#3htmlize@rdelim@i}%
    fi
  fi
  htmlize@next@i
}
{catcode`$=12relax%
  gdefhtmlize@inlinemathshift@replace#1#2htmlize@rdelim@iii{%
    xag@addto@macroxahtmlize@outputxa{inlinemathleftdelim}%
        advancemathmodecounter{1}%
        gdefmathtext{}%
        gdefaftertext{}%
        htmlize@inlinemath@recursive@i#2htmlize@rdelim@i%
        xdefhtmlize@remaining@text{expandoncemathtext%
                                     otherbackslash inlinemathrightdelim{}%
                                     expandonceaftertext}%
  }%
}%
makeatother

Basically, the recursive command htmlize@inlinemath@recursive@i ends when the dollar sign is encountered. The point is that it processes together and whatever symbol comes after. Therefore, it will not end when $ is encountered.

Answered by mgk on April 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP