如何在方程式中添加勘误表(来自勘误表包)但 Latex 抱怨:
! LaTeX Error: Not in outer par mode.
例子:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amssymb, amsmath}
\usepackage{errata}
\begin{document}
\begin{align*}
\erratumReplace{typo}{$a_{10}$}{$a_{00}$} &= 2 \cdot 6 + (-1)\cdot 4\cdot 1 = 8\\
a_{10} &= -(18 - 4) = -14\\
a_{20} &= (3 -2) = 1\\
||A||&= 1\cdot 8 + 0\cdot (-14)+ 5\cdot 1 =13\;.
\end{align*}
\end{document}
答案1
我创建了一个新命令\erratumMathReplace
,该命令(至少应该)在数学模式下有效。但由于勘误表是在脚注中添加的,而这些在环境中不起作用align
(感谢@daleif 指出这一点),我创建了一个附加命令,\erratumMathPrint
它将打印脚注。
的工作\erratumMathReplace
方式与原来的相同\erratumReplace
,并且\erratumMathPrint
必须在数学环境结束后发出。
代码:
\usepackage{marginnote}
\makeatletter
\newcommand{\erratumMathReplace}[4][]{% keyvals, explanation, old, new
\setkeys{erratum}{#1}\stepcounter{erratum}\record@erratum{#2}%
\marginnote{Err(\arabic{erratum})}\immediate\typeout{Erratum!}%
[#4]_r^{\arabic{erratum}}%
\gdef\erratumMath@new{#2}%
\gdef\erratumMath@old{#3}}
\newcommand{\erratumMathPrint}{%
\footnotetext[\value{erratum}]{\text{{\scshape{Erratum!}}%
\@ifundefined{erratum@type}{}{(\erratum@type)} \(\erratumMath@new\) (original text was: ``\(\erratumMath@old\)'')}}}
\makeatother
例子:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amssymb, amsmath}
\usepackage{errata}
\usepackage{marginnote}
\makeatletter
\newcommand{\erratumMathReplace}[4][]{% keyvals, explanation, old, new
\setkeys{erratum}{#1}\stepcounter{erratum}\record@erratum{#2}%
\marginnote{Err(\arabic{erratum})}\immediate\typeout{Erratum!}%
[#4]_r^{\arabic{erratum}}%
\gdef\erratumMath@new{#2}%
\gdef\erratumMath@old{#3}}
\newcommand{\erratumMathPrint}{%
\footnotetext[\value{erratum}]{\text{{\scshape{Erratum!}}%
\@ifundefined{erratum@type}{}{(\erratum@type)} \(\erratumMath@new\) (original text was: ``\(\erratumMath@old\)'')}}}
\makeatother
\begin{document}
\begin{align*}% Note that the arguments to \erratumMathReplace don't go inside $$
\erratumMathReplace{typo}{a_{10}}{a_{00}} &= 2 \cdot 6 + (-1)\cdot 4\cdot 1 = 8\\
a_{10} &= -(18 - 4) = -14\\
a_{20} &= (3 -2) = 1\\
||A||&= 1\cdot 8 + 0\cdot (-14)+ 5\cdot 1 =13\;.
\end{align*}
\erratumMathPrint% Printing the footnote
\end{document}
答案2
您可以强制errata
使用\marginnote
而不是\marginpar
,这是问题的主要根源。
您还需要\mbox
围绕errata
命令。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amssymb, amsmath}
\usepackage[show]{errata}
\usepackage{marginnote,xpatch}
\xpatchcmd{\erratumAdd}{\marginpar}{\marginnote}{}{}
\xpatchcmd{\erratumDelete}{\marginpar}{\marginnote}{}{}
\xpatchcmd{\erratumReplace}{\marginpar}{\marginnote}{}{}
\xpatchcmd{\erratum}{\marginpar}{\marginnote}{}{}
\xpatchcmd{\enderratum}{\marginpar}{\marginnote}{}{}
\newcommand{\matherratumAdd}[3][]{%
\mbox{\erratumAdd[#1]{#2}{\ensuremath{#3}}}%
}
\newcommand{\matherratumDelete}[3][]{%
\mbox{\erratumDelete[#1]{#2}{\ensuremath{#3}}}%
}
\newcommand{\matherratumReplace}[4][]{%
\mbox{\erratumReplace[#1]{#2}{\ensuremath{#3}}{\ensuremath{#4}}}%
}
\begin{document}
\begin{align*}
\matherratumReplace{typo}{a_{10}}{a_{00}} &= 2 \cdot 6 + (-1)\cdot 4\cdot 1 = 8\\
a_{10} &= -(18 - 4) = -14\\
a_{20} &= (3 -2) = 1\\
||A||&= 1\cdot 8 + 0\cdot (-14)+ 5\cdot 1 =13\;.
\end{align*}
$\matherratumReplace{typo}{x}{y}$
$\matherratumAdd{typo}{a}$
\erratumAdd{x}{y}
\clearpage
\PrintErrata
\end{document}
但是,您不会看到脚注。恐怕那太复杂了。