summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/hep-acronym/hep-acronym-implementation.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/hep-acronym/hep-acronym-implementation.dtx')
-rw-r--r--macros/latex/contrib/hep-acronym/hep-acronym-implementation.dtx156
1 files changed, 134 insertions, 22 deletions
diff --git a/macros/latex/contrib/hep-acronym/hep-acronym-implementation.dtx b/macros/latex/contrib/hep-acronym/hep-acronym-implementation.dtx
index ded23522db..43a4dd900e 100644
--- a/macros/latex/contrib/hep-acronym/hep-acronym-implementation.dtx
+++ b/macros/latex/contrib/hep-acronym/hep-acronym-implementation.dtx
@@ -1,6 +1,6 @@
% \iffalse meta-comment
%
-% Copyright (C) 2019 by Jan Hajer
+% Copyright (C) 2019-2023 by Jan Hajer
% -----------------------------------
%
% This file may be distributed and/or modified under the
@@ -18,29 +18,27 @@
% \iffalse
%
%<package>\NeedsTeXFormat{LaTeX2e}[2005/12/01]
-%<package>\ProvidesPackage{hep-acronym}[2022/11/01 v1.1 Acronyms using glossaries]
-%<documentation>\ProvidesFile{hep-acronym-documentation.tex}[2022/11/01 v1.1 hep-acronym documentation]
+%<package>\ProvidesPackage{hep-acronym}[2023/07/01 v1.2 Acronyms using glossaries]
+%<documentation>\ProvidesFile{hep-acronym-documentation.tex}[2023/07/01 v1.2 hep-acronym documentation]
%
%<*documentation>
-
\RequirePackage[l2tabu, orthodox]{nag}
\documentclass{ltxdoc}
+
+\renewcommand\theCodelineNo{\rmfamily\tstyle\footnotesize\arabic{CodelineNo}}
+\AtBeginEnvironment{macrocode}{\renewcommand{\ttdefault}{clmt}}
+\renewcommand{\MacroFont}{\codestyle}
\AtBeginDocument{\DeleteShortVerb{\|}}
\AtBeginDocument{\MakeShortVerb{\"}}
-
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\usepackage{hologo}
-\usepackage[parskip]{hep-paper}
+\usepackage[parskip,oldstyle,font=10pt]{hep-paper}
\bibliography{bibliography}
-
\acronym{PDF}{portable document format}
-
-\MacroIndent=1.5em
-\AtBeginEnvironment{macrocode}{\renewcommand{\ttdefault}{clmt}}
%</documentation>
%<*driver>
@@ -72,7 +70,7 @@
% Right brace \} Tilde \~}
%
% \changes{v1.0}{2021/09/01}{Initial version of the style file.}
-% \changes{v1.1}{2022/11/01}{Bug fixes.}
+% \changes{v1.1}{2023/07/01}{Bug fixes.}
%
% \ifshort
%<*documentation>
@@ -101,7 +99,7 @@ Acronyms are implemented using the \software{glossaries-extra} package \cite{glo
It can be loaded using "\usepackage{hep-acronym}".
\DescribeMacro{\acronym}
-The "\acronym"\meta{*}\oarg{typeset abbreviation}\marg{abbreviation}\meta{*}\marg{definition}\oarg{plural\linebreak[4]definition} macro generates the singular "\"\meta{abbreviation} and plural "\"\meta{abbreviation}"s" macros.
+The "\acronym"\meta{*}\oarg{typeset abbreviation}\marg{abbreviation}\meta{*}\marg{definition}\oarg{plural definition} macro generates the singular "\"\meta{abbreviation} and plural "\"\meta{abbreviation}"s" macros.
The first star prevents the addition of an \enquote{s} to the abbreviation plural.
The second star restores the \hologo{TeX} default of swallowing subsequent white space.
@@ -119,12 +117,13 @@ The "\sentence" macro ensures that the directly following abbreviation is capita
The "\shortacronym" and "\longacronym" macros are drop-in replacements of the "\acronym" macro showing only the short or long form of their acronym.
\DescribeMacro{\resetacronym}
-\DescribeMacro{\dummyacronym}
The first use form of the acronym can be enforced by resetting the acronym counter with "\resetacronym"\marg{key}.
+\DescribeMacro{\dummyacronym}
If the acronym counter equals one at the end of the document the short form of the acronym is not introduced.
Placing a "\dummyacronym"\marg{key} at the end of the document ensures that the short form is introduced.
+\DescribeMacro{warning}
In order to reduce the number of potentially conflicting packages the \software{glossaries} package is loaded without any glossary style.
In the case that the glossary should be printed additional packages must be loaded via \eg "\usepackage{glossary-list}".
@@ -147,11 +146,32 @@ In the case that the glossary should be printed additional packages must be load
%
%<*package>
%
+% Define a hepacronym namespace for the options using the \software{kvoptions} package \cite{kvoptions}.
+% \begin{macrocode}
+\RequirePackage{kvoptions}
+\SetupKeyvalOptions{
+ family=hepacronym,
+ prefix=hepacronym@
+}
+% \end{macrocode}
+%
+% \begin{macro}{hyper}
+% Define the "hyper" option controlling the hyperlink to the first appearance of the acronyms.
+% \begin{macrocode}
+\DeclareBoolOption[true]{hyper}
+% \end{macrocode}
+% \end{macro}
+%
+% Process options.
+% \begin{macrocode}
+\ProcessKeyvalOptions*
+% \end{macrocode}
+%
% Load the base package \cite{glossaries, glossaries-extra} and set the abbreviation style.
% \begin{macrocode}
\PassOptionsToPackage{nostyles}{glossaries-extra}
\RequirePackage{glossaries-extra}
-\setabbreviationstyle{long-hyphen-short-hyphen}
+% \setabbreviationstyle{long-hyphen-short-hyphen}
% \end{macrocode}
% Use the entry count feature.
% \begin{macrocode}
@@ -191,6 +211,12 @@ In the case that the glossary should be printed additional packages must be load
\@ifpackageloaded{hyperref}{\pdfstringdefDisableCommands{#1}}{}%
}
% \end{macrocode}
+% Deactivate hyperrefs if requested.
+% \begin{macrocode}
+\ifhepacronym@hyper\else
+ \glsdisablehyper
+\fi
+% \end{macrocode}
%
% \begin{macro}{\begin@sentence}
% Mark the beginning of a paragraph as if it would follow a full stop using the \software{everyhook} package \cite{everyhook}.
@@ -290,7 +316,7 @@ In the case that the glossary should be printed additional packages must be load
% Provide the singular acronym macro in math mode.
% \begin{macrocode}
\expandafter\mathdef\csname#3\endcsname{%
- \text{\glsxtrshort{#3}}\@gls@increment@currcount{#3}%
+ \mathinner{\text{\glsxtrshort{#3}}}\@gls@increment@currcount{#3}%
}
% \end{macrocode}
% Provide the plural acronym macro.
@@ -309,7 +335,7 @@ In the case that the glossary should be printed additional packages must be load
% Provide the plural acronym macro in math mode.
% \begin{macrocode}
\expandafter\mathdef\csname#3s\endcsname{%
- \text{\glsxtrshortpl{#3}}\@gls@increment@currcount{#3}%
+ \mathinner{\text{\glsxtrshortpl{#3}}}\@gls@increment@currcount{#3}%
}
% \end{macrocode}
% Provide an enforced long form.
@@ -364,7 +390,7 @@ In the case that the glossary should be printed additional packages must be load
% Provide the singular acronym macro in math mode.
% \begin{macrocode}
\expandafter\mathdef\csname#3\endcsname{%
- \text{\IfNoValueTF{#2}{#3}{#2}}%
+ \mathinner{\text{\IfNoValueTF{#2}{#3}{#2}}}%
}
% \end{macrocode}
% Provide the plural acronym macro.
@@ -383,7 +409,7 @@ In the case that the glossary should be printed additional packages must be load
% Provide the plural acronym macro in math mode.
% \begin{macrocode}
\expandafter\mathdef\csname#3s\endcsname{%
- \text{\IfBooleanTF{#1}{#3}{\IfNoValueTF{#2}{#3s}{#2s}}}%
+ \mathinner{\text{\IfBooleanTF{#1}{#3}{\IfNoValueTF{#2}{#3s}{#2s}}}}%
}%
% \end{macrocode}
% Ensure that long form also exists.
@@ -438,6 +464,89 @@ In the case that the glossary should be printed additional packages must be load
}
% \end{macrocode}
% \end{macro}
+
+% \begin{macro}{\acronymalternative}
+% Allow for alternative long text in abbreviation.
+% \begin{macrocode}
+\NewDocumentCommand{\acronymalternative}{mmsm}{%
+% \end{macrocode}
+% Store it in the "useri" field.
+% \begin{macrocode}
+ \GlsXtrSetField{#1}{useri}{#4}%
+% \end{macrocode}
+% Define the acronym
+% \begin{macrocode}
+ \expandafter\newcommand\csname#2\endcsname[1][]{%
+% \end{macrocode}
+% Redirect the relevant macros to the useri field.
+% \begin{macrocode}
+ \let\hep@glsaccesslong\glsaccesslong%
+ \let\hep@Glsaccesslong\Glsaccesslong%
+ \let\glsaccesslong\glsuseri%
+ \let\Glsaccesslong\Glsuseri%
+% \end{macrocode}
+% Execute abbreviation macros.
+% \begin{macrocode}
+ \if@begin@of@sentence{%
+ \ifglsused{#1}{\cgls{#1}[##1]}{\cGls{#1}[##1]}%
+ }{\cgls{#1}[##1]}%
+% \end{macrocode}
+% Undo the redirection.
+% \begin{macrocode}
+ \let\glsaccesslong\hep@glsaccesslong%
+ \let\Glsaccesslong\hep@Glsaccesslong%
+% \end{macrocode}
+% Spacing code.
+% \begin{macrocode}
+ \ifnum\glsentrycurrcount{#1}>1\relax%
+ \IfBooleanTF{#3}{}{\@\xspace}%
+ \else\@\xspace\fi%
+ }
+% \end{macrocode}
+% Redirect \PDF code to original acronym.
+% \begin{macrocode}
+ \hep@disable{\expandafter\def\csname#2\endcsname{%
+ \csname#1\endcsname }%
+ }
+% \end{macrocode}
+% Redirect math macro to original acronym.
+% \begin{macrocode}
+ \expandafter\mathdef\csname#2\endcsname{%
+ \mathinner{\text{\glsxtrshort{#1}}}\@gls@increment@currcount{#1}%
+ }
+% \end{macrocode}
+% Provie long version of acronym.
+% \begin{macrocode}
+ \expandafter\newcommand\csname#2long\endcsname[1][]{%
+% \end{macrocode}
+% Redirect relevant macros.
+% \begin{macrocode}
+ \let\hep@glsentrydesc\glsentrydesc%
+ \let\hep@Glsentrydesc\Glsentrydesc%
+ \renewrobustcmd*{\glsentrydesc}[1]{\@gls@entry@field{#1}{useri}}%
+ \renewrobustcmd*{\Glsentrydesc}[1]{\@Gls@entry@field{#1}{useri}}%
+% \end{macrocode}
+% Execute relevant macro.
+% \begin{macrocode}
+ \if@begin@of@sentence{\Glsdesc*{#1}[##1]}{\glsdesc*{#1}[##1]}%
+ \IfBooleanTF{#3}{}{\@\xspace}%
+% \end{macrocode}
+% Undo redefinition.
+% \begin{macrocode}
+ \let\glsentrydesc\hep@glsentrydesc%
+ \let\Glsentrydesc\hep@Glsentrydesc%
+ }
+% \end{macrocode}
+% Provie \PDF code.
+% \begin{macrocode}
+ \hep@disable{%
+ \expandafter\def\csname#2long\endcsname{%
+ \@Gls@entry@field{#1}{useri} %
+ }%
+ }%
+}
+% \end{macrocode}
+% \end{macro}
% Silence warning if no acronyms are defined.
% \begin{macrocode}
\renewcommand*{\@gls@write@entrycounts}{%
@@ -562,8 +671,8 @@ An acronym extension for glossaries
## Introduction
-The `hep-acronym` package provides an acronym macro based on the `glossaries` package.
-It can be loaded using `\usepackage{hep-acronym}`.
+The `hep-acronym` package provides an acronym macro based on the
+`glossaries` package. It can be loaded using `\usepackage{hep-acronym}`.
## Author
@@ -571,8 +680,11 @@ Jan Hajer
## License
-This file may be distributed and/or modified under the conditions of the `LaTeX` Project Public License, either version 1.3c of this license or (at your option) any later version.
-The latest version of this license is in `http://www.latex-project.org/lppl.txt` and version 1.3c or later is part of all distributions of LaTeX version 2005/12/01 or later.
+This file may be distributed and/or modified under the conditions of the
+`LaTeX` Project Public License, either version 1.3c of this license or
+(at your option) any later version. The latest version of this license is
+in `http://www.latex-project.org/lppl.txt` and version 1.3c or later is
+part of all distributions of LaTeX version 2005/12/01 or later.
% \end{macrocode}
%
%</readme>