我正在尝试使用\usepackage{moodle}
Overleaf 编译我的 LaTeX。
每当我想要包含美元符号时\$
,它都无法正确编译。
在文档中包含美元符号的正确方法是什么,以便 LaTeX 可以正确编译?
\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}`
如果\$
前面有“1”,则编译时会出现错误。如果删除,则\$
一切正常。
准确地说,错误信息如下:
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 doe\ETC.
! 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!
答案1
该moodle
包必须将 TeX 材料转换为 HTML。具体来说,它尝试抓取内联数学环境 ( $...$
) 的内容。当找到左分隔符(第一个$
)时,该包 (自 0.5 版起) 采用的策略是盲目寻找下一个美元符号。虽然这在大多数情况下都有效,但您的示例表明,\$
在此类环境中使用的字符会欺骗moodle
。
这个问题至少有两个解决方法:
- 如果可能的话,避免在内联数学环境中使用美元符号(参见@egreg 的评论)。包裹
moodle
不会被愚弄\$$1$
。 - 使用 LaTeX 的内联数学分隔符
\(...\)
。该包moodle
不会被 欺骗\(\$1\)
。
如果这些解决方法都不行,您可以moodle
通过在序言中添加以下代码来修复的内部命令。
\makeatletter
\long\def\htmlize@inlinemath@recursive@i#1#2#3\htmlize@rdelim@i{%
\def\test@i{#1}%
\ifx\test@i\@otherbackslash
\g@addto@macro\mathtext{#1#2}%
\def\htmlize@next@i{\xa\htmlize@inlinemath@recursive@i#3\htmlize@rdelim@i}%
\else
\ifx\test@i\@otherdollar
\let\htmlize@next@i=\relax
\g@addto@macro\aftertext{#2#3}%
\else
\g@addto@macro\mathtext{#1}%
\def\htmlize@next@i{\xa\htmlize@inlinemath@recursive@i#2#3\htmlize@rdelim@i}%
\fi
\fi
\htmlize@next@i
}
{\catcode`\$=12\relax%
\gdef\htmlize@inlinemathshift@replace#1#2\htmlize@rdelim@iii{%
\xa\g@addto@macro\xa\htmlize@output\xa{\inlinemathleftdelim}%
\advancemathmodecounter{1}%
\gdef\mathtext{}%
\gdef\aftertext{}%
\htmlize@inlinemath@recursive@i#2\htmlize@rdelim@i%
\xdef\htmlize@remaining@text{\expandonce\mathtext%
\otherbackslash inlinemathrightdelim{}%
\expandonce\aftertext}%
}%
}%
\makeatother
基本上,递归命令\htmlize@inlinemath@recursive@i
在遇到美元符号时结束。关键是它会一起处理后面的任何符号。因此,遇到\
时它不会结束。\$