如何在 latexdiff 中使用双下标?

如何在 latexdiff 中使用双下标?

我有两个 tex 文件,它们只是具有带双下标的不同字符:

%test_1.tex
\documentclass{article}
\begin{document}

30th percentile of $S_{\textrm{NO$_2$}}$

\end{document}
%test_2.tex

\documentclass{article}
\begin{document}

30th percentile of $V_{\textrm{NO$_2$}}$

\end{document}

我试图获得test_diff.tex这样的结果:latexdiff test_1.tex test_2.tex > test_diff.tex

但是,运行时出现此错误pdflatex test_diff.tex

No file test_diff.aux.
(/usr/local/texlive/2022/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
))
Runaway argument?
{$S\SUBSCRIPT {\textrm {NO$}\DIFdelend \DIFaddbegin \DIFadd {$V_{\textrm \ETC.
! File ended while scanning use of \DIFdel.
<inserted text>
                \par
<*> test_diff.tex

以下为主要内容test_diff.tex

\begin{document}

30th percentile of \DIFdelbegin \DIFdel{$S\SUBSCRIPT{\textrm{NO$}\DIFdelend \DIFaddbegin \DIFadd{$V_{\textrm{NO$}\DIFaddend _2$}}$

\end{document}

答案1

您可以使用chemformula

第一个文件

\documentclass{article}
\usepackage{chemformula}

\begin{document}

30th percentile of $S_{\ch{NO2}}$

\end{document}

第二个文件

\documentclass{article}
\usepackage{chemformula}

\begin{document}

30th percentile of $V_{\ch{NO2}}$

\end{document}

差异文件

\documentclass{article}
%DIF LATEXDIFF DIFFERENCE FILE
%DIF DEL nodue1.tex   Sun Jan  8 16:06:16 2023
%DIF ADD nodue2.tex   Sun Jan  8 16:07:42 2023
\usepackage{chemformula}
%DIF PREAMBLE EXTENSION ADDED BY LATEXDIFF
%DIF UNDERLINE PREAMBLE %DIF PREAMBLE
\RequirePackage[normalem]{ulem} %DIF PREAMBLE
\RequirePackage{color}\definecolor{RED}{rgb}{1,0,0}\definecolor{BLUE}{rgb}{0,0,1} %DIF PREAMBLE
\providecommand{\DIFadd}[1]{{\protect\color{blue}\uwave{#1}}} %DIF PREAMBLE
\providecommand{\DIFdel}[1]{{\protect\color{red}\sout{#1}}}                      %DIF PREAMBLE
%DIF SAFE PREAMBLE %DIF PREAMBLE
\providecommand{\DIFaddbegin}{} %DIF PREAMBLE
\providecommand{\DIFaddend}{} %DIF PREAMBLE
\providecommand{\DIFdelbegin}{} %DIF PREAMBLE
\providecommand{\DIFdelend}{} %DIF PREAMBLE
\providecommand{\DIFmodbegin}{} %DIF PREAMBLE
\providecommand{\DIFmodend}{} %DIF PREAMBLE
%DIF FLOATSAFE PREAMBLE %DIF PREAMBLE
\providecommand{\DIFaddFL}[1]{\DIFadd{#1}} %DIF PREAMBLE
\providecommand{\DIFdelFL}[1]{\DIFdel{#1}} %DIF PREAMBLE
\providecommand{\DIFaddbeginFL}{} %DIF PREAMBLE
\providecommand{\DIFaddendFL}{} %DIF PREAMBLE
\providecommand{\DIFdelbeginFL}{} %DIF PREAMBLE
\providecommand{\DIFdelendFL}{} %DIF PREAMBLE
%DIF COLORLISTINGS PREAMBLE %DIF PREAMBLE
\RequirePackage{listings} %DIF PREAMBLE
\RequirePackage{color} %DIF PREAMBLE
\lstdefinelanguage{DIFcode}{ %DIF PREAMBLE
%DIF DIFCODE_UNDERLINE %DIF PREAMBLE
  moredelim=[il][\color{red}\sout]{\%DIF\ <\ }, %DIF PREAMBLE
  moredelim=[il][\color{blue}\uwave]{\%DIF\ >\ } %DIF PREAMBLE
} %DIF PREAMBLE
\lstdefinestyle{DIFverbatimstyle}{ %DIF PREAMBLE
    language=DIFcode, %DIF PREAMBLE
    basicstyle=\ttfamily, %DIF PREAMBLE
    columns=fullflexible, %DIF PREAMBLE
    keepspaces=true %DIF PREAMBLE
} %DIF PREAMBLE
\lstnewenvironment{DIFverbatim}{\lstset{style=DIFverbatimstyle}}{} %DIF PREAMBLE
\lstnewenvironment{DIFverbatim*}{\lstset{style=DIFverbatimstyle,showspaces=true}}{} %DIF PREAMBLE
%DIF END PREAMBLE EXTENSION ADDED BY LATEXDIFF

\begin{document}

30th percentile of \DIFdelbegin \DIFdel{$S_{\ch{NO2}}$
}\DIFdelend \DIFaddbegin \DIFadd{$V_{\ch{NO2}}$
}\DIFaddend 

\end{document}

输出

在此处输入图片描述

在此处输入图片描述

在此处输入图片描述

没有chemformula

希望您被允许使用amsmath

\documentclass{article}
\usepackage{amsmath}

\begin{document}

30th percentile of $S_{\textup{NO\textsubscript{2}}}$

\end{document}

S改成V并运行之后latexdiff,输出与之前相同。

相关内容