1

The following example causes problem:

\documentclass{article}

\usepackage[colorlinks,linkcolor=blue]{hyperref}
\usepackage[ocgcolorlinks]{ocgx2}

\usepackage[record,acronym,shortcuts=ac]{glossaries-extra}

\usepackage{relsize}
\setabbreviationstyle[\acronymtype]{long-short-sm}

\usepackage{graphicx}
\newcommand{\myfmt}[1]{\scalebox{.35}{#1}}
\renewcommand*{\glsabbrvsmfont}[1]{\myfmt{#1}}%\renewcommand*{\glsnamefont}[1]{\myfmt{#1}}

\newcommand{\glspr}[1]{\glsxtrp{long}{#1}}

\GlsXtrLoadResources[src={entries}, selection={all}, type=\acronymtype, sort={letternumber-upperlower}]

\usepackage{filecontents}
\begin{filecontents}{entries.bib}
    @Acronym{c,
        long  = {ccc},
        short = {C}}
    @Acronym{bc,
        long   = {bbb \glspr{c}},
        parent = {c},
        short  = {BC}}
    @Acronym{abc,
        long   = {aaa \glspr{bc}},
        parent = {bc},
        short  = {ABC}}
    @Acronym{abc-d,
        description = {{}\glspr{abc}~--~\emph{ddd}},
        long        = {{}\glspr{abc} (d)},
        parent      = {abc},
        short       = {ABC-d}}
    @Acronym{abc-d-f,
        description = {{}\glspr{abc-d}~--~fff},
        long        = {{}\glspr{abc} (d, f)},
        parent      = {abc-d},
        short       = {ABC-d-f}}
    @Acronym{abc-d-g,
        description = {{}\glspr{abc-d}~--~ggg},
        long        = {{}\glspr{abc} (d, g)},
        parent      = {abc-d},
        short       = {ABC-d-g}}
    @Acronym{abc-e,
        description = {{}\glspr{abc}~--~\emph{eee}},
        long        = {{}\glspr{abc} (e)},
        parent      = {abc},
        short       = {ABC-e}}
    @Acronym{abc-e-f,
        description = {{}\glspr{abc-e}~--~fff},
        long        = {{}\glspr{abc} (e, f)},
        parent      = {abc-e},
        short       = {ABC-e-f}}
    @Acronym{abc-e-g,
        description = {{}\glspr{abc-e}~--~ggg},
        long        = {{}\glspr{abc} (e, g)},
        parent      = {abc-e},
        short       = {ABC-e-g}}
    @Acronym{h-bc,
        long   = {hhh \glspr{bc}},
        parent = {bc},
        short  = {H-BC}}
    @Acronym{iiii,
        long  = {ii ii ii ii},
        short = {IIII}}
    @Acronym{aaa,
        long  = {aaa aaa aaa},
        short = {AAA}}
    @Acronym{aab,
        long  = {aaa aaa bbb},
        short = {AAB}}
\end{filecontents}

\begin{document}

    \noindent Test: \ac{aab}, \ac{abc-e}, \ac{abc-e-g}.

    \printunsrtglossary[type=\acronymtype,style=treegroup]

\end{document}

Undesired result.

While the desired result should look like this:

Desired result.

One thing is that acronyms referred to using \ac command in the document body are not visible in the resulting PDF. Though, they still occupy required space and their text is present in the output (as it can be copied and pasted elsewhere).

Also, the acronyms list is broken in the middle of the first entry that has description field starting with \gls-like command (abc-d, in this case). It is stated in the glossaries-extra manual that the package may have problems with such entries (and also that these commands should be preceded by empty groups {}):

If you really need nested commands, the safest method is

\newabbreviation{shtml}{shtml}{{}\glsxtrp{short}{ssi} enabled \glsxtrp{short}{html}}

but be aware that it may have some unexpected results occasionally.

Nevertheless, it does not seem to be the core issue here, because the provided MWE works properly after slight modifications in declarations not related directly to the nesting commands (as described below).


Some observations:

  1. Removing ocgcolorlinks option from ocgx2 package is a kind of a workaround, but definitely not a complete solution.
  2. Changing \scalebox{.35}{#1} to \scalebox{1}{#1} is a workaround as well, but the required effect is not achieved (probably in such case the unnecessary \scalebox command is just not applied at all).
  3. Importing glossaries-extra package before hyperref also seems to help, but then the colored links for acronyms are lost.
  4. Changing \newcommand{\glspr}[1]{\glsxtrp{long}{#1}} to, e.g., \newcommand{\glspr}[1]{SOMETEXT\glsxtrp{long}{#1}} seems to repair the problem with broken acronym list, but then SOMETEXT is shown multiple times within the list and the acronyms in document body still do not show up.
  5. Might be quite obvious, but changing \renewcommand*{\glsabbrvsmfont}[1]{\myfmt{#1}} to \renewcommand*{\glsnamefont}[1]{\myfmt{#1}} solves the problem with acronyms in the document body (as graphicx's \scalebox-based \myfmt command is no longer appied to them), but the underlying problem persists and the acronyms list is still affected (broken).
1

With ocgx2 package option ocgcolorlinks, portions of the link text that are scaled or put in frameboxes, as well as graphics included with \includegraphics need special treatment. Just put \ocglinkprotect{...} around them.

In the present case:

\newcommand{\myfmt}[1]{\ocglinkprotect{\scalebox{.35}{#1}}}
  • 1
    This completely solves the underlying problem. – Peter Aug 8 '18 at 18:09
2

The same problem can be demonstrated with a much smaller example:

\documentclass{article}

\usepackage[colorlinks,linkcolor=blue]{hyperref}
\usepackage[ocgcolorlinks]{ocgx2}

\usepackage{graphicx}
\newcommand{\myfmt}[1]{\scalebox{.35}{#1}}

\begin{document}
\hypertarget{test}{Test Target}.

\hyperlink{test}{Test Link}.

\hyperlink{test}{\myfmt{Test Link}}.

\myfmt{\hyperlink{test}{Test Link}}.

\end{document}

The second link is present but invisible:

Test Target. Test Link. . Test Link.

The link text can still be copied, so it's present in the PDF.

The third link is visible and has the desired effect.

Returning to glossaries-extra, unfortunately the abbreviation font is inside the hyperlink, replicating the second link example above, so the same result occurs.

The only way of shifting a formatting command outside the hyperlink is when the formatting command is part of \glstextformat (or given by the textformat attribute) combined with the hyperoutside=false setting. This would affect the full form on first use and so can't be used for just the short form format.

If you only have text in your short form (and don't need to scale images), then I recommend that you use \textscale instead of \scalebox. For example:

\documentclass{article}

\usepackage[colorlinks,linkcolor=blue]{hyperref}
\usepackage[ocgcolorlinks]{ocgx2}

\usepackage{relsize}
\newcommand{\myfmt}[1]{\textscale{.35}{#1}}

\begin{document}
\hypertarget{test}{Test Target}.

\hyperlink{test}{Test Link}.

\hyperlink{test}{\myfmt{Test Link}}.

\myfmt{\hyperlink{test}{Test Link}}.
\end{document}

Test Target. Test Link. Test Link. Test Link.

This works both when it's inside and outside of the hyperlink.

\documentclass{article}

\usepackage[colorlinks,linkcolor=blue]{hyperref}
\usepackage[ocgcolorlinks]{ocgx2}

\usepackage[record,acronym,shortcuts=ac]{glossaries-extra}

\usepackage{relsize}
\setabbreviationstyle[acronym]{long-short-sm}

\newcommand{\myfmt}[1]{\textscale{.35}{#1}}
\renewcommand*{\glsabbrvsmfont}[1]{\myfmt{#1}}

\newcommand{\glspr}[1]{\glsxtrp{long}{#1}}

\GlsXtrLoadResources[src={entries}, selection={all}, type=\acronymtype, sort={letternumber-upperlower}]

\usepackage{filecontents}
\begin{filecontents}{entries.bib}
    @Acronym{c,
        long  = {ccc},
        short = {C}}
    @Acronym{bc,
        long   = {bbb \glspr{c}},
        parent = {c},
        short  = {BC}}
    @Acronym{abc,
        long   = {aaa \glspr{bc}},
        parent = {bc},
        short  = {ABC}}
    @Acronym{abc-d,
        description = {{}\glspr{abc}~--~\emph{ddd}},
        long        = {{}\glspr{abc} (d)},
        parent      = {abc},
        short       = {ABC-d}}
    @Acronym{abc-d-f,
        description = {{}\glspr{abc-d}~--~fff},
        long        = {{}\glspr{abc} (d, f)},
        parent      = {abc-d},
        short       = {ABC-d-f}}
    @Acronym{abc-d-g,
        description = {{}\glspr{abc-d}~--~ggg},
        long        = {{}\glspr{abc} (d, g)},
        parent      = {abc-d},
        short       = {ABC-d-g}}
    @Acronym{abc-e,
        description = {{}\glspr{abc}~--~\emph{eee}},
        long        = {{}\glspr{abc} (e)},
        parent      = {abc},
        short       = {ABC-e}}
    @Acronym{abc-e-f,
        description = {{}\glspr{abc-e}~--~fff},
        long        = {{}\glspr{abc} (e, f)},
        parent      = {abc-e},
        short       = {ABC-e-f}}
    @Acronym{abc-e-g,
        description = {{}\glspr{abc-e}~--~ggg},
        long        = {{}\glspr{abc} (e, g)},
        parent      = {abc-e},
        short       = {ABC-e-g}}
    @Acronym{h-bc,
        long   = {hhh \glspr{bc}},
        parent = {bc},
        short  = {H-BC}}
    @Acronym{iiii,
        long  = {ii ii ii ii},
        short = {IIII}}
    @Acronym{aaa,
        long  = {aaa aaa aaa},
        short = {AAA}}
    @Acronym{aab,
        long  = {aaa aaa bbb},
        short = {AAB}}
\end{filecontents}

\begin{document}

    \noindent Test: \ac{aab}, \ac{abc-e}, \ac{abc-e-g}.

    \printunsrtglossary[type=\acronymtype,style=treegroup]

\end{document}

image of document

(Unrelated: the optional argument of \setabbreviationstyle should be a category label. The command \acronymtype is used to reference a glossary not a category. In the original MWE, \acronymtype happens to expand to the same value as the required category label, but they aren't necessarily the same so it's best not to use \acronymtype in contexts that expect a category label.)

  • This explains the underlying cause and answers the original question. However, in actual document, horizontal and vertical scaling factors are different (e.g., \scalebox{.8}[.7]{#1}). Although no images are to be scaled, relsize's \textscale command uses just one scaling factor parameter, so the desired effect cannot be fully achieved. The visible differences might quite subtle, but I am curious whether it is possible to overcome this limitation, i.e., to scale text inside hyperlink independently in both dimensions. Also, thank you for the remark about mislabeled category. – Peter Jul 31 '18 at 17:59
  • @Peter It might be worth asking a follow-up question specifically focussing on using \scalebox inside \hyperlink (with ocgx2 but without glossaries). This question and the underlying cause might have been missed by people with more in-depth knowledge of graphicx, hyperref and ocgx2. – Nicola Talbot Aug 1 '18 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.