cgnieder / acro

acronyms for LaTeX
LaTeX Project Public License v1.3c
40 stars 9 forks source link

Empty `foreign` shows empty parentheses & commands not expanding inside `foreign-babel` #241

Open StickySli opened 2 years ago

StickySli commented 2 years ago

I'm trying to write an article in two languages simultaneously using babel. I need to define some acronyms that usually have a definition in both languages but use the same short acronym. I have defined the following command to switch between languages quickly:

% example: \langsubs[catalan]{Hello World!}{Hola Món!}
\newcommand{\langsubs}[3][catalan]{%
  \iflanguage{english}{#2}{}%
  \iflanguage{#1}{#3}{}%
}

My acsetup contains:

\acsetup{
    make-links ,
    format/short = \textsc ,
    foreign/display = false,
    locale/format = \textit ,
    list/locale/display ,
    list/template = longtable ,
    list/sort ,
}

Using TeX Live for windows with acro version 61762 (3.7), babel version 62203 (3.73). Compiling with pdflatex and biber.

1st issue: Trying to use command withing foreign-babel does not get expanded

Example that does not work:

\DeclareAcronym{gpu}{
    short = GPU ,
    long = {\langsubs{graphics processing unit}{unitat de procés gràfic}} ,
    long-plural-form = {\langsubs{}{unitats de procés gràfic}} ,
    foreign = {\langsubs{}{graphics processing unit}},
    foreign-babel = {\langsubs{}{english}} ,
}

Error output:

c:/Users/creep/OneDrive/.tfg/build/main.tex:43: Package babel Error: You haven't defined the language '\langsubs {}{english}' yet.
(babel)                Perhaps you misspelled it or your installation
(babel)                is not complete.

See the babel package documentation for explanation.
Type  H <return>  for immediate help.
 ...                              

Expected outcome

I would expect that ACRO could expand the command like the other commands do just fine, since babel can't recognize \langsubs {}{english}.

2nd issue: Empty foreign makes empty parentheses

Commenting out the foreign-babel and compiling with english, outputs the following document: image

Expected outcome

I would expect that the parentheses that show (english: ) should not appear in this case. This should be similat to setting plural = ,. Disabling list/locale/display in acsetup just shows () after the long acronym.

Workaround

Works fine, but it's a bit long:

\langsubs{
    \DeclareAcronym{gpu}{
        short = GPU ,
        long = graphics processing unit ,
    }
}{
    \DeclareAcronym{gpu}{
        short = GPU ,
        long = unitat de procés gràfic ,
        long-plural-form = unitats de procés gràfic ,
        foreign = graphics processing unit ,
        foreign-babel = english ,
    }
}

The pdf output of the previous example: image

StickySli commented 2 years ago

I have an idea for the second issue: use babel's \iflanguage to check if foreign is different that the document's main language. If true, display foreign, otherwise hide it. Example:

\DeclareAcronym{gpio}{
    short = GPIO ,
    long = general-purpose inputs/output ,
    foreign = entrada/sortida per a un ús general ,
    foreign-babel = english ,
}

This seems counterintuitive since it would display if the document's language id different than english "general-purpose inputs/output (GPIO, english: entrada/sortida per a un ús general)" but this is similar to how Wikipedia articles display the foreign meaning.

cgnieder commented 2 years ago

Would it be please possible for you to post a real MWE?

Otherwise just a suggestion: you can easily redefine acro's templates which use the foreign property to include the language check.