# Problem with using glossaries-extra with ocgcolorlinks option of the ocgx2 package and scalebox-based glsabbrvsmfont/glsnamefont commands

The following example causes problem:

\documentclass{article}

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

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

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

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

\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}


While the desired result should look like this:

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.

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}}}

• This completely solves the underlying problem. – Peter Aug 8 '18 at 18:09

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

\documentclass{article}

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

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

\end{document}


The second link is present but invisible:

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{relsize}
\newcommand{\myfmt}[1]{\textscale{.35}{#1}}

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

\end{document}


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

\documentclass{article}

\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}}

\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}


(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