
後約瑟夫·賴特 (Joseph Wright) 的部落格文章,我想用mhchem
在chemfig
.一切都很順利,直到我決定在acro
包包中包含縮寫。在以下 MWE 中,縮寫詞被定義為已使用,但不包含在縮寫詞列表中。
\documentclass{article}
\usepackage{acro}
\usepackage{chemfig}
\usepackage[version=4]{mhchem}
\DeclareAcronym{boc}{short=Boc,long=\textit{tert}-butyloxycarbonyl}
% From http://www.texdev.net/2012/08/25/exploring-chemfig-customising-appearance/
\makeatletter
\def\CF@node@content{%
\expandafter\expandafter\expandafter%\expandafter\expandafter%
\printatom\expandafter\expandafter\expandafter%\expandafter\expandafter%
{\csname atom@\number\CF@cnt@atomnumber\endcsname}%
\ensuremath{\CF@node@strut}%
}
\makeatother
\renewcommand*{\printatom}[1]{{\ce{#1}}}
\begin{document}
\sffamily
\acifused{boc}{Boc is used}{Boc is not used}
\chemfig{\acs{boc}HN-R-NH2}
\acifused{boc}{Boc is used}{Boc is not used}
\printacronyms
\end{document}
當部落格文章中的程式碼被刪除時,一切又恢復正常,但我真的很喜歡能夠\ce
在\chemfig
.此外,它\chemfig
使用無襯線文字字體而不是襯線數學字體,這正是我想要的。
我嘗試在巨集\expandafter
周圍使用五個 s \printatom
。這確實解決了首字母縮略詞問題,而且字體仍然與周圍的無襯線文字字體相同,但解析方式\ce
不再正確。注意非下標2:
任何關於如何實現兩者acro
並mhchem
在其中工作的建議chemfig
將不勝感激。
答案1
由於您的重新定義,該\acs
命令被處理多次,但作為第一次處理(這是有根據的猜測)僅用於測量來自 acro 的寫入命令未執行的內容,因此它不會寫入\acro@used@once
輔助文件需要,但僅\acro@used@twice
來自實際排版。
align
如果您在內部(已測試)使用 acro,並且可能tabularx
以及其他處理其內容兩次的環境,您也會得到類似的行為。所以恕我直言,這是一個錯誤:acro 應該檢查這種情況。
您應該通知作者,作為解決方法,您可以嘗試以下方法。請注意,從 acro 的角度來看,該鍵已被使用了兩次。因此,針對「單一」出現的特殊樣式是行不通的。
\documentclass{article}
\usepackage{acro}
\usepackage{chemfig,amsmath}
\usepackage[version=4]{mhchem}
\DeclareAcronym{boc}{short=Boc,long=\textit{tert}-butyloxycarbonyl}
%% From http://www.texdev.net/2012/08/25/exploring-chemfig-customising-appearance/
\makeatletter
\def\CF@node@content{%
\expandafter\expandafter\expandafter%\expandafter\expandafter%
\printatom\expandafter\expandafter\expandafter%\expandafter\expandafter%
{\csname atom@\number\CF@cnt@atomnumber\endcsname}%
\ensuremath{\CF@node@strut}%
}
\ExplSyntaxOn
\cs_set_protected:Npn \acro@used@twice #1#2#3#4
{
\bool_if:cF {g__acro_#1_in_list_bool}
{\acro@used@once {#1}{#2}{#3}{#4}}
\cs_gset_nopar:cpn {acro@#1@twice} {#1}
\tl_if_empty:nF {#2#3#4}
{ \seq_gput_right:cn {g__acro_#1_pages_seq} { {#2}{#3}{#4} } }
}
\ExplSyntaxOff
\makeatother
\renewcommand*{\printatom}[1]{{\ce{#1}}}
\begin{document}
\sffamily
\acifused{boc}{Boc is used}{Boc is not used}
\chemfig{\acs{boc}HN-R-NH2}
\acifused{boc}{Boc is used}{Boc is not used}
\printacronyms
\end{document}