在 chemfig 中使用 acro 和 mhchem

在 chemfig 中使用 acro 和 mhchem

約瑟夫·賴特 (Joseph Wright) 的部落格文章,我想用mhchemchemfig.一切都很順利,直到我決定在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:

mhchem 未解析的內容

任何關於如何實現兩者acromhchem在其中工作的建議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}

相關內容