[Tex/LaTex] How to add translation to long form of acronym

acronyms

I am currently using the acronym package to handle acronyms/abbreviations in my thesis.

I am writing in German, but I use a couple of English acronyms because either no German acronym exists or the English one simply more commonly used. So when introducing the acronym, I want/need to use the German word in text (as "long" form) but I want to include the English long form in parentheses alongside the (English) acronym. And of course, both German and English should show up in the list of acronyms.

  • German Term: Steuergerät
  • English Term: Electronic Control Unit
  • Acronym: ECU

So in my text I'd like to have:

…. Steuergerät( Electronic Control Unit, ECU) ….

and later simply have

…. ECU ….

In the list of acronyms, it should show up as:

ECU Steuergerät (Electronic Control Unit)

or

ECU Electronic Control Unit (Steuergerät)

Is there a way to include a translation in the long version of an acronym?

EDIT: As pointed out by @NicolaTalbot, the use case is the same than Using the glossaries package for English acronyms in German documents. Is there a way to achieve this with the acronym package as well or do I need to switch packages?

Best Answer

As I already said in the comments: acro provides the foreign key for cases like this. Nonetheless: here is a way to achieve what you want with acronym. The usage is similar to acronym's \acroextra. The code below defines a command \acroforeign{<foreign long form>} that is to be placed inside the second mandatory argument of \acro:

enter image description here

\documentclass{article}
\usepackage{acronym}

% provides \AtBeginEnvironment, \patchcmd and \csdef:
\usepackage{etoolbox}

\makeatletter
\newcommand{\acroforeign}[1]{}

% patch the environment to print the foreign definition:
\AtBeginEnvironment{acronym}{%
  \def\acroforeign#1{ (#1)}%
}

% patch the acronym definition to safe the foreign definition:
\expandafter\patchcmd\csname AC@\AC@prefix{}@acro\endcsname
  {\begingroup}
  {\begingroup\def\acroforeign##1{\csdef{ac@#1@foreign}{##1, }}}
  {}
  {\fail}

% %   renew the first output to include the foreign definition if given:
\renewcommand*{\@acf}[2][\AC@linebreakpenalty]{%
  \ifAC@footnote
    \acsfont{\csname ac@#2@foreign\endcsname\AC@acs{#2}}%
    \footnote{\AC@placelabel{#2}\AC@acl{#2}{}}%
  \else
    \acffont{%
      \AC@placelabel{#2}\AC@acl{#2}%
      \nolinebreak[#1] %
      \acfsfont{(\acsfont{\csname ac@#2@foreign\endcsname\AC@acs{#2}})}%
    }%
  \fi
  \ifAC@starred\else\AC@logged{#2}\fi
}
\makeatother

\begin{document}

First: \ac{ECU}, \ac{BW}

Subsequent: \ac{ECU}, \ac{BW}

List:
\begin{acronym}[ECU]
  \acro{ECU}{Steuerger\"at\acroforeign{Electronic Control Unit}}
  \acro{BW}{Baden-W\"urttemberg}
\end{acronym}

\end{document}