3

Given the following MWE, is there a way to change the location of the abbreviated form in first use (full), so that it does not always appear after the long form is printed?

\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}

enter image description here

If not, could there be a new set of commands to use within the \DeclareAcronym block? So the declaration could instead look like

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

Where \short would be replaced with a space (note there is no space before \short) followed by the parenthesized short form? Similar commands could be added for other arguments of \DeclareAcronym as necessary.

3
  • This is just opinion but you're pushing the automation quite hard. In this case I'd use a combination of \acl and \acs as the sentence structure is likely to be less than optimal if you switch forms automatically.
    – Chris H
    Jul 10, 2017 at 18:54
  • @ChrisH You're probably right, but I see LaTeX as a programming language for documents. I know it's just a typesetting language, but this is the sort of thing I assume could be implemented into the acro package directly. I was hoping Cle­mens might notice the question and just go for it, but I'm happy for alternatives.
    – twilsonco
    Jul 13, 2017 at 3:24
  • I could probably write something for acronym; in fact I've done something very similar before, though inserting the short form in the the long form would make it harder. What I meant was that automation is easier than writing nicely, especially taking into account the nested acronyms.
    – Chris H
    Jul 13, 2017 at 6:30

3 Answers 3

2

The \DeclareAcroFirstStyle macro could in future provide an interface to achieve this, but with the current options available to it I couldn't work something out, as it stands I could find two ways to do it but both with potential issues which interfere with other acro features.

By utilising the \acifused{<id>}{<true>}{<false>} macro we can adapt the long entry of \DeclareAcronym{grad}{<keys>} to change it's appearance according to whether the acronym rho has been used. Unfortunately it doesn't seem particularly easy to append text to the first appearance, instead I had to define a first-style which only printed the long-form and include the short-form in the long as

\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,
}

While this generates first appearances as desired, it doesn't play as nicely with \acl{grad}, which will still generate a bracketed short form as so

\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}

enter image description here


Alternatively acro allows for the manual creation of \ac-like commands, which we can use to construct something specifically for the grad acronym which will manually assemble the appropriate long or short form according to whether both the rho and grad (in the code below gradtwo) acronyms have been used.

\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

This has the advantage of leaving the long version untouched, and \acgrad is used instead of \ac{grad} with minimal extra diffiulty but any of the variants to do the equivalent of \Ac{grad}, \acp{grad} etc. must be manually defined in order for them to share the appropriate first appearance.

Comparing these two strategies

\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}

enter image description here

3
  • Thanks for the alternative solutions. This is probably the best I can hope for unless the capability is baked right into Acro.
    – twilsonco
    Jul 14, 2017 at 19:38
  • @twilsonco acro is under reasonably active development, you could always try suggesting something on the bitbucket issue tracker
    – Dai Bowen
    Jul 14, 2017 at 20:29
  • Thanks for the suggestion @Dai. I submitted a ticket to that effect.
    – twilsonco
    Jul 16, 2017 at 5:04
2

Since no one's provided an answer with the acro package, here's a solution using glossaries-extra. This defines a custom style ofother that checks if the user1 field has been set. If it has then the value is taken as the label for the other symbol and "of ..." is done (otherwise it does nothing). This is done with the custom \ofother command, which takes the label as the argument:

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

The custom ofother style that uses this command is:

\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}%
}

This uses the post-link hook to append \ofother{\glslabel} after the first use.

You can set different styles according to the entry's category. For example:

\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}

However, since \ofother does nothing if user1 hasn't been set, they can be given the same style with just the default abbreviation category:

\setabbreviationstyle{ofother}

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

Here's a complete document:

\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}

This produces:

First use: gradient (∇ρ) of electron charge density (ρ). Next use: ∇ρ. Here’s electron charge density (ρ). Reset all. First use again: electron charge density (ρ) and gradient (∇ρ) of electron charge density (ρ).

The first use of grad doesn't unset rho. If it needs to be unset at the same time, then this just requires a minor modification to \ofother:

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

If you want a list of all the symbols, the simplest method is to use \printunsrtglossary which will list all defined entries in the order of definition:

\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}

image of document with list of symbols

There are lots of predefined glossary styles if you don't like the default.

If you want to use hyperref make sure it's loaded before glossaries-extra:

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

(In general, hyperref needs to be loaded last. This is one of the few exceptions.)

If you get any "undefined control sequence errors" in the above example, check you have up-to-date versions of glossaries and glossaries-extra.

3
  • Wow and thanks! That's why you're a creator and I'm just a user. I've shied away from the glossary because it's so incredibly feature-rich. On the other hand, I switched from acronym to acro so I could get a few more features, and now I'm wishing acro had more. Perhaps the time has come to simply switch to glossary and gain the ability to do whatever I want. All I need to do is become as proficient in glossary as its creator!
    – twilsonco
    Jul 13, 2017 at 3:33
  • A SO sidenote: This may very well be the solution I go with. Given that, should I mark this as the answer, or should I wait for a solution using acro because that was the specific topic of the question?
    – twilsonco
    Jul 13, 2017 at 3:35
  • @twilsonco You could leave it a little while longer to see if any solutions with acro are provided, but I think if you mark an answer you can later switch to a different one if something more appropriate turns up. Jul 13, 2017 at 9:59
2

With yesterday's update to v2.8 acro has the property post which allows to prepend something to an acronym. There is also the command \aciffirst{true}{false} with which you can test if the acronym is used the first time:

\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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .