添加

添加

LaTeX在插入新的章節等時,非常適合調整編號,更重要的是調整編號的引用。

法律文件(和書籍),至少在德國,傾向於通過保持先前的編號不變來插入這些內容,但在插入之前使用數字,後跟一個小字母(a,b,c,...),以表明某些內容發生了變化(無論是在最後一刻,還是——這是非常重要的情況——與上一個版本相比)。

因為我認為很少有超過一個連續的腳註,所以我嘗試了以下(極其粗糙和骯髒的)黑客行為,如 MWE 中所示:

\documentclass{article}
\newcommand{\myextrafootnote}[1]{\renewcommand{\thefootnote}{\arabic{footnote}a}\footnote[\thefootnote]{#1}\renewcommand{\thefootnote}{\arabic{footnote}}}%
\begin{document}
This is the old text\footnote{foo}, followed by the new insert\myextrafootnote{New Exciting Stuff!!}, followed by the old next one.\footnote{bar}
\end{document}

可悲的是,它並沒有像我希望的那樣工作。雖然腳註本身看起來應該是這樣的: 註腳,中間有一些額外的內容

文字得到額外的a 添加在腳註之前:如下所示: 文本,比實際想要的更多

當然,理想情況下,它a也來自某種形式的計數器(我也嘗試過,但它變成了很多關於缺少參數的錯誤訊息,所以我放棄了它並決定更好地詢問專家..... .)所以如果雖然有不止一個連續添加的腳註,但它仍然可以正常工作[並且比現在更簡單]。

答案1

此指令的可選參數\footnote需要一個整數包含腳註的編號,而不是該編號的文字表示形式。所以,你應該使用

\footnote[\value{footnote}]{#1}

代替

\footnote[\thefootnote]{#1}

添加

那麼,多餘的「a」從哪裡來呢?為了理解這一點,讓我們逐步檢查錯誤代碼是如何

\footnote[\thefootnote]{#1}

由 TeX 消化。該巨集\thefootnote擴展(在OP使用它的上下文中)為1a,因此 (La)TeX 看到等價的

\footnote[1a]{...}

但是,正如已經說過的,它期望可選參數包含一個整數值;此整數值在本機指派給內部指令內的專用計數器(或者footnotempfootnote取決於上下文)\@xfootnote。此作業的代碼是(相當於)

<counter> = #1\relax

在我們的例子中,變成

<counter> = 1a\relax

但是a終止整數常數 1,因此也終止賦值;此時,該a標記被解釋為在水平方向上排版“a”字符的命令(IE,當前)模式。我們到了。

答案2

這裡新增了一個計數器,每次使用extrastuff時都會步進。\myextrafootnote

然而,由於使用了26,因此這種方式不可能有更多的添加。\alph{extrastuff}

如果您需要更多添加,alphalph用於增加計數器輸出的套件非常有用!

\documentclass{book}


\newcounter{extrastuff}[chapter]

\newcommand{\myextrafootnote}[1]{%
  \stepcounter{extrastuff}%
  \begingroup
  \renewcommand{\thefootnote}{\arabic{footnote}\alph{extrastuff}}%
  \footnote[\value{footnote}]{#1}%
  \endgroup
}%
\begin{document}

This is the old text\footnote{foo}, followed by the new insert\myextrafootnote{New Exciting Stuff!!}, followed by the old next one.\footnote{bar}

New however is this text\myextrafootnote{Really new Exciting Stuff!!}, followed by the old next one.\footnote{foobar}
\end{document}

在此輸入影像描述

更新

extrastuff使用腳註計數器重置:

\documentclass{book}


\newcounter{extrastuff}[footnote]

\newcommand{\myextrafootnote}[1]{%
  \stepcounter{extrastuff}%
  \begingroup
  \renewcommand{\thefootnote}{\arabic{footnote}\alph{extrastuff}}%
  \footnote[\value{footnote}]{#1}%
  \endgroup
}%
\begin{document}

This is the old text\footnote{foo}, followed by the new insert\myextrafootnote{New Exciting Stuff!!}, now for something completely different\myextrafootnote{Other top secret content}, followed by the old next one.\footnote{bar}

New however is this text\myextrafootnote{Really new Exciting Stuff!!}, followed by the old next one.\footnote{foobar}
\end{document}

答案3

這是短期思維的一個很好的例子。你的解決方案帶來的問題比它解決的問題還要多。您將如何標記下一次修訂的新腳註?

如果您需要顯示文件的兩個修訂版之間的更改,請提供 document-version-1.tex 和 document-version-2.tex 之間的“差異”,後者是最新修訂版。

請看一下,您可以透過在控制台視窗中latexdiff輸入來取得手冊。texdoc latexdiff基本上,這只是

latexdiff document-version-1.tex document-version-2.tex > document-diff.tex

然後開啟並編譯document-diff.tex。 PDF 包含所有變更。

您可以選擇刪除和新增的顏色和標記。我比較喜歡放類似的東西

\providecommand{\DIFadd}[1]{{\protect\color{blue}#1}} %DIF PREAMBLE
\providecommand{\DIFdel}[1]{{\protect\color{red}\protect\scriptsize{#1}}}

進入 document-diff.tex 的序言部分。

這樣做的優點是可以清楚地顯示文件兩個版本之間的差異。目前以及將來的任何修訂。

如果您期望進行多次修訂,請考慮使用版本控制系統,例如 git,然後使用 Latexbatchdiff,請參閱此處:https://tex.stackexchange.com/a/44092/4736

相關內容