更改首字母縮寫詞首次使用中縮寫形式的位置? (使用 acro.sty)

更改首字母縮寫詞首次使用中縮寫形式的位置? (使用 acro.sty)

給定以下MWE,有沒有辦法在第一次使用(完整)時更改縮寫形式的位置,以便在列印長形式後它不會總是出現?

\documentclass[]{article}
\usepackage{acro,bm}
\DeclareAcronym{rho}{
    short=$\rho$,
    long=electron charge density
}
\DeclareAcronym{grad}{
    short=$\bm{\nabla}$\hspace{-1.2pt}$\bm{\rho}$,
    long=gradient of \ac{rho}
}

\begin{document}

first use of grad:
\ac{grad}

would rather have:
gradient (\acs{grad}) of \acf{rho}

\end{document}

在此輸入影像描述

如果沒有,是否可以在區塊內使用一組新的命令\DeclareAcronym?所以聲明可以看起來像

\DeclareAcronym{grad}{
    short=$\bm{\nabla}$\hspace{-1.2pt}$\bm{\rho}$,
    long=gradient\short of \ac{rho}
}

哪裡\short將被替換為空格(注意 之前沒有空格\short),後面是帶括號的縮寫形式?\DeclareAcronym根據需要,可以為其他參數添加類似的命令。

答案1

\DeclareAcroFirstStyle巨集將來可以提供一個介面來實現此目的,但是根據當前可用的選項,我無法解決問題,就目前情況而言,我可以找到兩種方法來實現這一點,但這兩種方法都存在幹擾其他方法的潛在問題acro特徵。

透過使用\acifused{<id>}{<true>}{<false>}巨集,我們可以根據是否使用了縮寫來調整long的條目以更改其外觀。不幸的是,將文字附加到第一次外觀似乎並不特別容易,相反,我必須定義一個僅列印長格式並將短格式包含在長格式中的\DeclareAcronym{grad}{<keys>}rhofirst-style

\DeclareAcroFirstStyle{conditional}{inline}{
    only-long=true
}
\DeclareAcronym{grad}{
    short=$\bm{\nabla}$\hspace{-1.2pt}$\bm{\rho}$,
    long=gradient \acifused{rho}{of \ac{rho} (\acs{grad})}{(\acs{grad}) of \acl{rho} (\acs{rho})},
    first-style=conditional,
}

雖然這會根據需要產生第一次出現,但它與 的效果並不好\acl{grad},它仍然會產生一個括號內的縮寫形式,如下所示

\documentclass{article}
\usepackage{acro,bm}

\DeclareAcroFirstStyle{conditional}{inline}{
only-long=true
}

\DeclareAcronym{rho}{
    short=$\rho$,
    long=electron charge density,
}
\DeclareAcronym{grad}{
    short=$\bm{\nabla}$\hspace{-1.2pt}$\bm{\rho}$,
    long=gradient \acifused{rho}{of \ac{rho} (\acs{grad})}{(\acs{grad}) of \acl{rho} (\acs{rho})},
    first-style=conditional,
}
\DeclareAcronym{gradtwo}{
    short=$\bm{\nabla}$\hspace{-1.2pt}$\bm{\rho}$,
    long=gradient of \acs{rho}
}

\begin{document}
\ac{grad}

\acuse{rho}
\acf{grad}

\ac{grad}

\acl{grad}

\acreset{rho}
\acl{grad}
\end{document}

在此輸入影像描述


或者acro允許手動創建\ac類似命令,我們可以使用它來構造專門針對grad首字母縮寫詞的命令,該命令將根據是否使用了rhograd(在下面的代碼中)首字母縮略詞手動組裝適當的長形式或短形式。gradtwo

\ExplSyntaxOn
\NewDocumentCommand \acgrad {s}
{
    \acro_begin:
    \acro_reset_specials:
    \acro_check_and_mark_if:nn {#1}{gradtwo}
    \acro_if_acronym_used:nTF {gradtwo}
    {
        \acro_short:n {gradtwo}
    }{
        \acro_if_acronym_used:nTF {rho}
        {
            \acro_long:n {gradtwo}~(\acro_short:n {gradtwo})
        }{
            gradient~(\acro_short:n {gradtwo})~of~\acro_long:n {rho}~(\acro_short:n {rho})
        }
    }
    \acro_end:
}
\ExplSyntaxOff

這樣做的優點是保持long版本不變,並且\acgrad使用時具有最小的額外難度,\ac{grad}但任何與 等價的變體都必須手動定義,以便它們共享適當的首次外觀。\Ac{grad}\acp{grad}

比較這兩種策略

\documentclass[]{article}
\usepackage{acro,bm}

\DeclareAcroFirstStyle{conditional}{inline}{
only-long=true
}

\DeclareAcronym{rho}{
    short=$\rho$,
    long=electron charge density,
}
\DeclareAcronym{grad}{
    short=$\bm{\nabla}$\hspace{-1.2pt}$\bm{\rho}$,
    long=gradient \acifused{rho}{of \ac{rho} (\acs{grad})}{(\acs{grad}) of \acl{rho} (\acs{rho})},
    first-style=conditional,
}
\DeclareAcronym{gradtwo}{
    short=$\bm{\nabla}$\hspace{-1.2pt}$\bm{\rho}$,
    long=gradient of \acs{rho}
}

\ExplSyntaxOn
\NewDocumentCommand \acgrad {s}
{
    \acro_begin:
    \acro_reset_specials:
    \acro_check_and_mark_if:nn {#1}{gradtwo}
    \acro_if_acronym_used:nTF {gradtwo}
    {
        \acro_short:n {gradtwo}
    }{
        \acro_if_acronym_used:nTF {rho}
        {
            \acro_long:n {gradtwo}~(\acro_short:n {gradtwo})
        }{
            gradient~(\acro_short:n {gradtwo})~of~\acro_long:n {rho}~(\acro_short:n {rho})
        }
    }
    \acro_end:
}
\ExplSyntaxOff

\begin{document}
\ac{grad}

\acuse{rho}
\acf{grad}

\ac{grad}

%\acreset{rho}
\acl{grad}

\hrule

\acreset{rho}
\acgrad

\acreset{gradtwo}
\acgrad

\acgrad

\acl{gradtwo}
\end{document}

在此輸入影像描述

答案2

由於沒有人提供acro包的答案,這裡有一個使用的解決方案glossaries-extra。這定義了一個自訂樣式ofother,用於檢查該user1欄位是否已設定。如果有,則該值將被視為另一個符號的標籤,並且“of ...”已完成(否則不執行任何操作)。這是透過自訂\ofother命令完成的,該命令將標籤作為參數:

\newcommand*{\ofother}[1]{%
 \ifglshasfield{user1}{#1}%
 {\space of \glsentrylong{\glscurrentfieldvalue}
  (\glsxtrshort{\glscurrentfieldvalue})}%
 {}%
}

ofother使用此命令的自訂樣式是:

\newabbreviationstyle{ofother}
{%
  \renewcommand*{\CustomAbbreviationFields}{%
    name={\the\glsshorttok},
    sort={\the\glslabeltok},
    first={\the\glslongtok\space(\the\glsshorttok)},
    description={\the\glslongtok\protect\ofother{\the\glslabeltok}}
  }%
  \renewcommand*{\GlsXtrPostNewAbbreviation}{%
    \csdef{glsxtrpostlink\glscategorylabel}{%
      \glsxtrifwasfirstuse
      {%
        \ofother{\glslabel}%
      }%
      {}%
    }%
    \glshasattribute{\the\glslabeltok}{regular}%
    {%
      \glssetattribute{\the\glslabeltok}{regular}{false}%
    }%
    {}%
  }%
}
{%
  \GlsXtrUseAbbrStyleFmts{long-short}%
}

這使用後連結鉤子\ofother{\glslabel}在第一次使用後追加。

您可以根據條目的類別設定不同的樣式。例如:

\setabbreviationstyle[symbol]{long-short}    
\setabbreviationstyle[of]{ofother}

\newabbreviation[category=symbol]{rho}{$\rho$}{electron charge density}
\newabbreviation
 [category=of,user1=rho]
 {grad}
 {$\bm{\nabla}$\hspace{-1.2pt}$\bm{\rho}$}
 {gradient}

但是,由於如果未設定\ofother則不執行任何操作,因此可以為它們賦予相同的樣式,僅使用預設類別:user1abbreviation

\setabbreviationstyle{ofother}

\newabbreviation{rho}{$\rho$}{electron charge density}
\newabbreviation
 [user1=rho]
 {grad}
 {$\bm{\nabla}$\hspace{-1.2pt}$\bm{\rho}$}
 {gradient}

這是一個完整的文檔:

\documentclass{article}

\usepackage{bm}
\usepackage[shortcuts]{glossaries-extra}

\newcommand*{\ofother}[1]{%
 \ifglshasfield{user1}{#1}%
 {\space of \glsentrylong{\glscurrentfieldvalue}
  (\glsxtrshort{\glscurrentfieldvalue})}%
 {}%
}

\newabbreviationstyle{ofother}
{%
  \renewcommand*{\CustomAbbreviationFields}{%
    name={\the\glsshorttok},
    sort={\the\glslabeltok},
    first={\the\glslongtok\space(\the\glsshorttok)},
    description={\the\glslongtok\protect\ofother{\the\glslabeltok}}
  }%
  \renewcommand*{\GlsXtrPostNewAbbreviation}{%
    \csdef{glsxtrpostlink\glscategorylabel}{%
      \glsxtrifwasfirstuse
      {%
        \ofother{\glslabel}%
      }%
      {}%
    }%
    \glshasattribute{\the\glslabeltok}{regular}%
    {%
      \glssetattribute{\the\glslabeltok}{regular}{false}%
    }%
    {}%
  }%
}
{%
  \GlsXtrUseAbbrStyleFmts{long-short}%
}

\setabbreviationstyle{ofother}

\newabbreviation{rho}{$\rho$}{electron charge density}
\newabbreviation
 [user1=rho]
 {grad}
 {$\bm{\nabla}$\hspace{-1.2pt}$\bm{\rho}$}
 {gradient}

\begin{document}
First use: \ac{grad}.

Next use: \ac{grad}.

Here's \ac{rho}.

Reset all.\glsresetall

First use again: \ac{rho} and \ac{grad}.

\end{document}

這會產生:

首先使用:電子電荷密度(ρ)的梯度(∇ρ)。下次使用:∇ρ。這是電子電荷密度 (ρ)。重置全部。首先再次使用:電子電荷密度(ρ)和電子電荷密度(ρ)的梯度(∇ρ)。

第一次使用grad不會取消設定rho。如果需要同時取消設置,那麼只需要稍作修改\ofother

\newcommand*{\ofother}[1]{%
 \ifglshasfield{user1}{#1}%
 {\space of \glsentrylong{\glscurrentfieldvalue}
  (\glsxtrshort{\glscurrentfieldvalue}\glsunset{\glscurrentfieldvalue})}%
 {}%
}

如果您想要所有符號的列表,最簡單的方法是使用\printunsrtglossary它將按定義順序列出所有定義的條目:

\documentclass{article}

\usepackage{bm}
\usepackage[shortcuts]{glossaries-extra}

\newcommand*{\ofother}[1]{%
 \ifglshasfield{user1}{#1}%
 {\space of \glsentrylong{\glscurrentfieldvalue}
  (\glsxtrshort{\glscurrentfieldvalue}\glsunset{\glscurrentfieldvalue})}%
 {}%
}

\newabbreviationstyle{ofother}
{%
  \renewcommand*{\CustomAbbreviationFields}{%
    name={\the\glsshorttok},
    sort={\the\glslabeltok},
    first={\the\glslongtok\space(\the\glsshorttok)},
    description={\the\glslongtok\protect\ofother{\the\glslabeltok}}
  }%
  \renewcommand*{\GlsXtrPostNewAbbreviation}{%
    \csdef{glsxtrpostlink\glscategorylabel}{%
      \glsxtrifwasfirstuse
      {%
        \ofother{\glslabel}%
      }%
      {}%
    }%
    \glshasattribute{\the\glslabeltok}{regular}%
    {%
      \glssetattribute{\the\glslabeltok}{regular}{false}%
    }%
    {}%
  }%
}
{%
  \GlsXtrUseAbbrStyleFmts{long-short}%
}

\setabbreviationstyle{ofother}

\newabbreviation{rho}{$\rho$}{electron charge density}
\newabbreviation
 [user1=rho]
 {grad}
 {$\bm{\nabla}$\hspace{-1.2pt}$\bm{\rho}$}
 {gradient}

\begin{document}
First use: \ac{grad}.

Next use: \ac{grad}.

Here's \ac{rho}.

Reset all.\glsresetall

First use again: \ac{rho} and \ac{grad}.

\printunsrtglossary[title=Symbols,nogroupskip]

\end{document}

帶有符號列表的文檔圖像

許多預定義的術語表樣式如果你不喜歡預設的。

如果您想使用,hyperref請確保之前已加載glossaries-extra

\usepackage[colorlinks]{hyperref}
\usepackage[shortcuts]{glossaries-extra}

(一般情況下,hyperref需要最後加載。這是少數例外之一。)

如果您在上面的範例中遇到任何“未定義的控制序列錯誤”,請檢查您是否擁有最新版本的glossariesglossaries-extra

答案3

昨天更新的 v2.8具有允許在首字母縮略詞前面添加某些內容的acro屬性。post還有一個指令\aciffirst{true}{false}可以用來測試縮寫詞是否是第一次使用:

\documentclass{article}
\usepackage{acro,bm}

\DeclareAcronym{rho}{
  short = $\rho$,
  long  = electron charge density
}
\DeclareAcronym{grad}{
  short = $\bm{\nabla}$\hspace{-1.2pt}$\bm{\rho}$,
  long  = gradient ,
  post  = \aciffirst{ of \ac{rho}}{}
}

\begin{document}

first use of grad:
\ac{grad}

\acs{grad}

\end{document}

在此輸入影像描述

相關內容