Patch parameter of environment

environments

I'm using the taggedline environment from the tagpair package for source attributions in my examples. By default, these get printed in the document font. For less visual clutter, I had considered printing them at, say, \footnotesize. However, I haven't been able to find out how to patch the corresponding line in the environment definition with etoolbox or xpatch without redefining the whole environment in my document in order to change one line. Is this possible at all?

The taggedline environment takes the attribution tag as a parameter which is internally handled as \savebox{\t@g}{#2}. Basically, I want to place a formatting option like \footnotesize before the #2 part or do something to that effect, anyway.

\documentclass{article}

\usepackage{tagpair}
\usepackage{gb4e}

% Copied & adjusted from
% /usr/local/texlive/2021/texmf-dist/tex/latex/tagpair/tagpair.sty
\makeatletter
\renewenvironment{taggedline}[2][0.75]%
  {\def\linewidthfactor{#1}%
%  \savebox{\t@g}{#2}%
   \savebox{\t@g}{\footnotesize#2}% <- can this be done by etoolbox/xpatch?
   \ignorespaces}%
  {\unskip%
   \hfil\penalty0%
   \hskip1em%
   \hbox{}%
   \nobreak%
   \hfill%
   \begin{varwidth}[t]{\linewidthfactor\linewidth}
     \narrowraggedleft\strut\unhbox\t@g
   \end{varwidth}}
\makeatother

\begin{document}

\begin{exe}
\ex
\begin{taggedline}{(Example 2021: 123)}
\gll Dies ist ein Beispiel \\
     this is an example \\
\glt `This is an example.'
\end{taggedline}
\end{exe}

\end{document}

Linguistic example with interlinear gloss and attribution tag on the bottom right side

Best Answer

You would need to patch the macro \taggedline which is the internal representation for the begin of the environment with the same name. However, because this environment has an optional argument, patching this macro is a bit tricky using the \patchcmd macro of the etoolbox package.

But you can use \xpatchcmd macro of the xpatch package for this. Your code will be much shorter then:

\documentclass{article}

\usepackage{tagpair}
\usepackage{gb4e}

\usepackage{xpatch}
\xpatchcmd{\taggedline}{{#2}}{{\footnotesize#2}}{}{}

\begin{document}

\begin{exe}
\ex
\begin{taggedline}{(Example 2021: 123)}
\gll Dies ist ein Beispiel \\
     this is an example \\
\glt `This is an example.'
\end{taggedline}
\end{exe}

\end{document}

The output is the same as the output in your question.