這是一個後續問題圖表清單中的術語表溢出,其中有人詢問如何glossaries
將包的第一個使用方案與圖形標題中的術語表一起使用。我給了一個只要caption
包未加載就有效的答案。
\documentclass{article}
\usepackage{caption}
\usepackage[colorlinks]{hyperref}
\usepackage{glossaries}
\makeglossaries
\newglossaryentry{acr}{%
name = {ACR-name},%
description = {ACR-description},%
first = {ACR-first-description},%
}
\renewcommand{\glsdisplayfirst}[4]{#1 (1) #4}
\renewcommand{\glsdisplay}[4]{#1 (2+) #4}
\begin{document}
% \listoffigures %% even without \listoffigures the problem shows up
\begin{figure}[h]
\caption[Short title \glshyperlink{acr}]{Long title \gls{acr}}
\end{figure}
\printglossary
\end{document}
可以看出,如果沒有caption
圖形標題,則包含所需的詞彙表條目的第一個使用形式,但有了caption
它,則包含後續使用形式。
我怎樣才能在使用時保持它的工作caption
?
答案1
LaTeX 將標題放入臨時刮痕內\hbox
,測量其寬度。如果線寬小於線寬,盒子被重複用於排版標題。因此\gls
被稱為一次。但是,如果標題寬度超過行寬,則標題文字將設定兩次,這次作為段落。然後\gls
被調用兩次,您將獲得詞彙表項目第二個版本的輸出。
包caption
使行為更加可預測。如果singlelinecheck
設定了選項(預設),則標題文字始終設定兩次,第一次用於測量寬度以檢查文字是否適合一行,然後再次設定文字以獲得最終結果。使用 時singlelinecheck=false
,測量將被停用,且文字僅設定一次,但標題文字的居中位置會遺失。
解決方法是將結果放入\gls{acr}
臨時框中並在其中使用該框\caption
:
\documentclass{article}
\usepackage{caption}
\usepackage{glossaries}
\newsavebox\glsscratchbox
\makeglossaries
\newglossaryentry{acr}{%
name = {ACR-name},%
description = {ACR-description},%
first = {ACR-first-description},%
}
\renewcommand{\glsdisplayfirst}[4]{#1 (1) #4}
\renewcommand{\glsdisplay}[4]{#1 (2+) #4}
\begin{document}
\listoffigures %% even without \listoffigures the problem shows up
\begin{figure}[h]
\sbox\glsscratchbox{\gls{acr}}
\caption[Short title \glshyperlink{acr}]{Long title \unhcopy\glsscratchbox}
\end{figure}
\printglossary
\end{document}
(使用該命令\unhcopy
代替\usebox
(這是一個\copy
)。它會剝離外層\hbox
並允許以與行中其他空格相同的方式排版空格。否則 ( \usebox
) 重用框內的空格將始終具有自然寬度.)
解決方案\gls
在標題與包caption
更新:新增了 Axel Sommerfeldt 評論的簡化。
包包glossaries
必須記住首字母縮寫的第一次用法。我們的想法是,如果測量了標題的寬度,則停用此功能,但如果標題文字最終排版,則不停用此功能。
需要包caption
,因為它將測試與最終的排版步驟分開。它還提供了\caption@prepareslc
測量之前的宏,並在測量之前調用。暫時禁用\glsunset
測量。
\documentclass{article}
\usepackage{glossaries}
\usepackage{caption}
\makeatletter
\g@addto@macro\caption@prepareslc{%
\let\glsunset\@gobble
}
\makeatother
\makeglossaries
\newglossaryentry{acr}{%
name = {ACR-name},%
description = {ACR-description},%
first = {ACR-first-description},%
}
\renewcommand{\glsdisplayfirst}[4]{#1 (1) #4}
\renewcommand{\glsdisplay}[4]{#1 (2+) #4}
\begin{document}
\listoffigures
\begin{figure}[h]
\caption[Short title \glshyperlink{acr}]{Long title \gls{acr}}
\end{figure}
\printglossary
\end{document}
細化
如果\gls{acr}
使用,則為縮寫詞設定全域標誌acr
以記住縮寫詞使用的狀態。因此後續調用可以使用較短的形式。如果僅測量標題文本,則先前的解決方案會跳過狀態設定。因此,當最終設定標題文字時,狀態並未改變。
然而,有一種情況會被忽視。標題文字\gls
多次包含相同的縮寫詞,包括其第一次使用。那麼先前的解決方案將包含首字母縮略詞在測量步驟中的使用的首字母縮略詞的第一個使用形式,因為那裡的狀態設定已被停用。
這是透過允許測量步驟中縮寫詞的正常狀態變化來解決的,但記住第一次用法。在字幕文字最終排版之前會進行重置。
進一步說明:
\if@capmeasure
引入了一個開關。通常設定為\iffalse
。當在內部檢查文字的寬度時\caption
,則將其設為\iftrue
。- 需要包
caption
,因為它將測試與最終的排版步驟分開。它還提供了\caption@prepareslc
測量之前的巨集。兩者都在同一個本地組中執行。因此添加\@capmeasurefalse
到就足夠了\caption@prepareslc
。分組結束後開關自動重設。 - 測量後,第一個縮寫詞使用的狀態被重置。
- 軟體包
glossaries
'\glsunset
已進行修補,以尊重首字母縮略詞的設定\if@capmeasure
並記住首字母縮略詞的用法。
完整範例:
\documentclass{article}
\usepackage{glossaries}
\usepackage{caption}
\makeatletter
\newif\if@capmeasure
\g@addto@macro\caption@prepareslc{%
\global\let\after@capmeasure\@empty
\aftergroup\after@capmeasure
\@capmeasuretrue
}
\CheckCommand*{\glsunset}[1]{%
\glsdoifexists{#1}{%
\expandafter \global \csname glo@#1@flagtrue\endcsname
}%
}
\renewcommand*{\glsunset}[1]{%
\glsdoifexists{#1}{%
\if@capmeasure
\expandafter\ifx\csname ifglo@#1@flag\expandafter\endcsname
\csname iftrue\endcsname
\else
% first use
\g@addto@macro\after@capmeasure{\glsreset{#1}}%
\fi
\fi
\global\csname glo@#1@flagtrue\endcsname
}%
}
\makeatother
\makeglossaries
\newglossaryentry{acr}{%
name = {ACR-name},%
description = {ACR-description},%
first = {ACR-first-long-description},%
}
\renewcommand{\glsdisplayfirst}[4]{#1\textsuperscript{(1)}#4}
\renewcommand{\glsdisplay}[4]{#1\textsuperscript{(2+)}#4}
\begin{document}
\listoffigures
\begin{figure}[h]
\caption[Short title \glshyperlink{acr}]%
{Long title \textit{\gls{acr}} and \gls{acr}}
\end{figure}
\printglossary
\end{document}
答案2
使用glossaries-extra
你有兩種選擇。看這裡。
- 您隨時可以
\glsxtrshort
在字幕內通話。由於顯而易見的原因,這些不會觸發首次使用。如果您還想避免連結並且不希望這些條目出現在使用 建立的術語表列表中,您也可以使用noindex
和選項。這讓我們想到:hyper=false
\printglossaries
- 預測此用法,
glossaries-extra
包括命令系列\glsfmtshort
。這些與相應的命令相同\glsxtrshort[noindex,hyper=false]
。因此,您有幾個類似的命令,涵蓋單數和複數形式、短、長和完整形式,以及小寫、首字母大寫和完整大寫形式。