如何在数学中嵌入勘误表?

如何在数学中嵌入勘误表?

如何在方程式中添加勘误表(来自勘误表包)但 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}

但是,您不会看到脚注。恐怕那太复杂了。

在此处输入图片描述

相关内容