cgnieder / acro

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

Template for using footnotes in "normal" acronyms #90

Closed cgnieder closed 4 years ago

cgnieder commented 7 years ago

Original report by Anonymous.


The MWE from http://tex.stackexchange.com/questions/236362 does not support footnotes in normal acronyms. See:

\documentclass{article}

% for demonstration purposes only: make the page small!
\usepackage[paperheight=20\baselineskip]{geometry}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@article{Smar1992,
  author    = {Smarr, Larry and Catlett, Charles E},
  journal   = {Communications of the ACM},
  number    = {6},
  pages     = {44--52},
  publisher = {ACM},
  title     = {Metacomputing},
  volume    = {35},
  year      = {1992}
}
\end{filecontents*}
\usepackage{acro}[2015-04-08]
\usepackage[style=ieee]{biblatex}
\addbibresource{\jobname.bib}
\acsetup{single,sort}

% make \footnote and \url robust commands, needs package `etoolbox':
\robustify\footnote
\robustify\url

\newif\ifacrousefootnote
\newcommand\acfootnote[1]{\ifacrousefootnote\footnote{#1}\fi}

\ExplSyntaxOn
\NewAcroCommand \aclu
  {
    \acro_is_used:nF {#1}
      { \acrousefootnotetrue \acro_cite: }
    \acro_long:n {#1}
  }
\NewAcroCommand \Aclu
  {
    \acro_if_acronym_used:nF {#1}
      { \acrousefootnotetrue \acro_cite: }
    \acro_first_upper:
    \acro_long:n {#1}
  }
\ExplSyntaxOff

\DeclareAcronym{Metacomputing}{
  short     = {metacomputing} ,
  long      = {metacomputing} ,
  cite      = {Smar1992} ,
  long-post = {\acfootnote{\url{http://example.org` ,
  class     = exclude
}

\DeclareAcronym{foo}{
  short     = {foo} ,
  long      = {foo bar baz},
  long-post = {\acfootnote{\url{http://example.org` ,
}

\begin{document}

\Ac{foo} and later \ac{foo} - footnotes not working.

\Aclu{Metacomputing} and later \aclu{Metacomputing}.

\printacronyms[exclude-classes=exclude]

\printbibliography

\end{document}
cgnieder commented 7 years ago

Original comment by Alexander Willner (Bitbucket: [Alexander Willner](https://bitbucket.org/Alexander Willner), ).


Probably just add:

    \RenewAcroCommand\ac%
      {
        \acro_if_acronym_used:nF {#1}
          { \acrousefootnotetrue\acro_cite: }
        \acro_use:n {#1}
      }
    \RenewAcroCommand\Ac%
      {
        \acro_if_acronym_used:nF {#1}
          { \acrousefootnotetrue\acro_cite: }
        \acro_first_upper:
        \acro_use:n {#1}
      }
cgnieder commented 6 years ago

Original comment by Clemens Niederberger (Bitbucket: cgnieder, GitHub: cgnieder).


I don't quite understand your question – why don't you just use the normal \footnote command? \acfootnote obviously is a command created for a special purpose!

#!latex

\DeclareAcronym{foo}{
  short     = {foo} ,
  long      = {foo bar baz},
  long-post = {\footnote{\url{http://example.org` ,
}
cgnieder commented 6 years ago

Original comment by Clemens Niederberger (Bitbucket: cgnieder, GitHub: cgnieder).


This needs clarification. Until then I'll put this on hold.

cgnieder commented 6 years ago

Original comment by Alexander Willner (Bitbucket: [Alexander Willner](https://bitbucket.org/Alexander Willner), ).


I clarified the issue a bit:

#!latex

\documentclass{article}

% for demonstration purposes only: make the page small!
\usepackage[paperheight=20\baselineskip]{geometry}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@article{Smar1992,
  author    = {Smarr, Larry and Catlett, Charles E},
  journal   = {Communications of the ACM},
  number    = {6},
  pages     = {44--52},
  publisher = {ACM},
  title     = {Metacomputing},
  volume    = {35},
  year      = {1992}
}
\end{filecontents*}
\usepackage{biblatex}
\addbibresource{\jobname.bib}

\usepackage{url}
\usepackage{acro}
\acsetup{single,sort}

% make \normaltnote and \url robust commands, needs package `etoolbox':
\robustify\footnote
\robustify\url

\ExplSyntaxOn
\NewAcroCommand \aclu
  {
    \acro_is_used:nF {#1}
      { \acro_cite: }
    \acro_long:n {#1}
  }
\NewAcroCommand \Aclu
  {
    \acro_if_acronym_used:nF {#1}
      { \acro_cite: }
    \acro_first_upper:
    \acro_long:n {#1}
  }
\ExplSyntaxOff

\DeclareAcronym{special}{
  short     = {special} ,
  long      = {special acronym} ,
  long-post = {\footnote{\url{http://example.org` ,
  cite      = {Smar1992} ,
  class     = exclude
}

\DeclareAcronym{normal}{
  short     = {normal} ,
  long      = {normal acronym},
  long-post = {\footnote{\url{http://myexample.org` ,
}

\begin{document}

This is a \ac{normal}. When \ac{normal} is used again, the footnotes work fine.
This is a \aclu{special} that is being used to include for example default footnotes and references.
When \aclu{special} is used a second time, analog to the reference, the footnote should only be shown once.

\printacronyms[exclude-classes=exclude]

\end{document}
cgnieder commented 5 years ago

Original comment by Clemens Niederberger (Bitbucket: cgnieder, GitHub: cgnieder).


I understand now. The example is a bit incorrect, though. The footnote is also repeated in the “normal” case (use \acl{normal} to see this – the footnote is appended to every call of the long form).

Probably a new property similar to the cite property is needed…

cgnieder commented 5 years ago

Original comment by Clemens Niederberger (Bitbucket: cgnieder, GitHub: cgnieder).


BTW: as as intermediate solution a combination of \footnote and \acfootnote could be used:

\newif\ifacrousefootnote
\newcommand\acfootnote[1]{\ifacrousefootnote\footnote{#1}\fi}

\ExplSyntaxOn
\NewAcroCommand \aclu
  {
    \acro_is_used:nF {#1}
      { \acrousefootnotetrue \acro_cite: }
    \acro_long:n {#1}
  }
\NewAcroCommand \Aclu
  {
    \acro_if_acronym_used:nF {#1}
      { \acrousefootnotetrue \acro_cite: }
    \acro_first_upper:
    \acro_long:n {#1}
  }
\ExplSyntaxOff

\DeclareAcronym{special}{
  short     = {special} ,
  long      = {special acronym} ,
  long-post = {\acfootnote{\url{http://example.org` , % <<< 
  cite      = {Smar1992} ,
  class     = exclude
}

\DeclareAcronym{normal}{
  short     = {normal} ,
  long      = {normal acronym},
  long-post = {\footnote{\url{http://myexample.org` % <<<
}

cgnieder commented 4 years ago

Original comment by Clemens Niederberger (Bitbucket: cgnieder, GitHub: cgnieder).


Removing version: 2.10 (automated comment)

cgnieder commented 4 years ago

Original comment by Clemens Niederberger (Bitbucket: cgnieder, GitHub: cgnieder).


Starting with version 2.11 (to be released today or tomorrow) there will be a property before-citation which can then be used:

\documentclass{article}

% for demonstration purposes only: make the page small!
\usepackage[paperheight=20\baselineskip]{geometry}

\begin{filecontents*}{\jobname.bib}
@article{Smar1992,
  author    = {Smarr, Larry and Catlett, Charles E},
  journal   = {Communications of the ACM},
  number    = {6},
  pages     = {44--52},
  publisher = {ACM},
  title     = {Metacomputing},
  volume    = {35},
  year      = {1992}
}
\end{filecontents*}
\usepackage{biblatex}
\addbibresource{\jobname.bib}

\usepackage{url}
\usepackage{acro}
\acsetup{single,sort}

\ExplSyntaxOn
\NewAcroCommand \aclu
  {
    \acro_is_used:nF {#1}
      { \acro_cite: }
    \acro_long:n {#1}
  }
\NewAcroCommand \Aclu
  {
    \acro_if_acronym_used:nF {#1}
      { \acro_cite: }
    \acro_first_upper:
    \acro_long:n {#1}
  }
\ExplSyntaxOff

\DeclareAcronym{special}{
  short     = {special} ,
  long      = {special acronym} ,
  before-citation = {\footnote{\url{http://example.org` ,
  cite      = {Smar1992} ,
  class     = exclude
}

\DeclareAcronym{normal}{
  short     = {normal} ,
  long      = {normal acronym},
  long-post = {\footnote{\url{http://myexample.org` ,
}

\begin{document}

This is a \ac{normal}. When \ac{normal} is used again, the footnotes work
fine.  This is a \aclu{special} that is being used to include for example
default footnotes and references.  When \aclu{special} is used a second time,
analog to the reference, the footnote should only be shown once.

\printacronyms[exclude-classes=exclude]

\end{document}

cgnieder commented 4 years ago

Original comment by Clemens Niederberger (Bitbucket: cgnieder, GitHub: cgnieder).


New option added in commit 72d741c which solves the issue.

cgnieder commented 4 years ago

Original comment by Alexander Willner (Bitbucket: [Alexander Willner](https://bitbucket.org/Alexander Willner), ).


Thank you. However, with version `2.11` your MWE above results in

Missing number, treated as zero.

<to be read again>

\g__acro_#3_used_bool

l.38 }

cgnieder commented 4 years ago

In version 3 I'd use it this way:

\documentclass{article}
\usepackage[T1]{fontenc}
% for demonstration purposes only: make the page small!
\usepackage[paperheight=20\baselineskip]{geometry}

\begin{filecontents*}{\jobname.bib}
@article{Smar1992,
  author    = {Smarr, Larry and Catlett, Charles E},
  journal   = {Communications of the ACM},
  number    = {6},
  pages     = {44--52},
  publisher = {ACM},
  title     = {Metacomputing},
  volume    = {35},
  year      = {1992}
}
\end{filecontents*}
\usepackage{biblatex}
\addbibresource{\jobname.bib}

\usepackage{url}
\usepackage{acro}

\DeclareAcronym{special}{
  short     = {special} ,
  long      = {special acronym} ,
  long-post = {\acroiffirstT{\footnote{\url{http://special.org}}}} ,
  cite      = {Smar1992} ,
  first-style = long ,
  tag       = exclude
}

\DeclareAcronym{normal}{
  short     = {normal} ,
  long      = {normal acronym},
  long-post = {\acroiffirstT{\footnote{\url{http://normal.org}}}}
}

\begin{document}

This is a \ac{normal}. When \ac{normal} or \acl{normal} are used again, the
footnotes work fine.  This is a \ac{special} that is being used to include for
example default footnotes and references.  When \ac{special} is used a second
time, analog to the reference, the footnote should only be shown once.

\printacronyms[exclude=exclude]

\end{document}

image

AlexanderWillner commented 4 years ago

Now that I found this issue again, #161 might be a duplicate. The new MWE here seems to work for me.