2

In trying to create a custom acro list style with a longtable and repeating heading, I started working my way through some LaTeX3 code more than I have in the past. I am used to patching with etoolbox's \patchcmd, but was stumped when trying to change a Template created via some code in acro.sty.

Goal

I want to change/add variables to the \DeclareAcroListStyle procedure to allow lines of the tables to be added before and after the acronym content, but inside the longtable environment. This would allow, for example, a header row with \endhead to be inserted to support a multiple-page table.

Minimum Working Example

This MWE gives a table and an example of how I would want the code to operate.

\documentclass{article}
\usepackage{acro,longtable}

\DeclareAcronym{test}{short = ST, long  = Some Test}

% Define a new format type
\DeclareAcroListStyle{newstyle}{table}{
table = longtable,
table-spec = ll,
before = This text is before the \texttt{\textbackslash begin\{...\}} element.,
after = \noindent This text is after the \texttt{\textbackslash end\{...\}} element.,
%%% Want to add these variables to put header into table:
% beforeinner = \hrule Acronym & Definition \\\endhead,
% afterinner = \hrule
}
\acsetup{list-style=newstyle}

\begin{document}
\noindent This is \ac{test}.
\printacronyms
\end{document}

Changes in the source code

I have solved my overall problem by copying and modifying the acro.sty in its entirety. Now, I am trying to get this done via a patch, so I don't have to copy the entire style file. The portion that I had to edit was lines 1795-1837 (6 lines added in code below, current version of acro package being v2.6e 2016/09/04).

% `table' template:
\DeclareTemplateInterface {acro-list} {table} {2}
  {
    table       : tokenlist = tabular ,
    table-spec  : tokenlist = lp{.7\linewidth} ,
    foreign-sep : tokenlist = {~} ,
    reverse     : boolean   = false ,
    before      : tokenlist = ,
    after       : tokenlist = ,
    beforeinner : tokenlist = ,  %%% ADDED
    afterinner  : tokenlist =    %%% ADDED
  }

\DeclareTemplateCode {acro-list} {table} {2}
  {
    table       = \l__acro_list_table_tl      ,
    table-spec  = \l__acro_list_table_spec_tl ,
    foreign-sep = \l__acro_foreign_sep_tl ,
    reverse     = \l__acro_list_reverse_long_extra_bool ,
    before      = \l__acro_list_before_tl ,
    after       = \l__acro_list_after_tl ,
    beforeinner = \l__acro_list_beforeinner_tl ,   %%% ADDED
    afterinner  = \l__acro_list_afterinner_tl      %%% ADDED
  }
  {
    \AssignTemplateKeys
    \acro_activate_hyperref_support:
    \bool_if:NTF \l__acro_list_reverse_long_extra_bool
      {
        \cs_set_protected:Npn \acro_print_list_entry:nnnn ##1##2##3##4
          { ##1 & ##3 ##2 ##4 \tabularnewline }
      }
      {
        \cs_set_protected:Npn \acro_print_list_entry:nnnn ##1##2##3##4
          { ##1 & ##2 ##3 ##4 \tabularnewline }
      }
    \acro_build_list_entries:Nnn \l__acro_list_entries_tl {#1} {#2}
    \use:x
      {
        \exp_not:V \l__acro_list_before_tl
        \exp_not:N \begin { \exp_not:V \l__acro_list_table_tl }
          { \exp_not:V \l__acro_list_table_spec_tl }
        \exp_not:V \l__acro_list_beforeinner_tl %%% ADDED
        \exp_not:V \l__acro_list_entries_tl
        \exp_not:V \l__acro_list_afterinner_tl  %%% ADDED
        \exp_not:N \end { \exp_not:V \l__acro_list_table_tl }
        \exp_not:V \l__acro_list_after_tl
      }
  }

It seems like I could modify the template interface after creation with xtemplate's \EditInstance, but I haven't actually confirmed that yet.

I can't figure out if/how I would be able to modify the template code in any similar fashion.


I would entertain any easier methods of solving the original problem (adding running header to longtable style with acro) in comments, but the real question is patching the template code in LaTeX3.

  • I did very much the same here: tex.stackexchange.com/q/295827/5049 – clemens Jan 11 '17 at 8:33
  • This other question gives good info as well; I tried this first, but was stuck without really knowing about \ExplSyntaxOn and \tl_new:N yet...! – cslstr Jan 12 '17 at 3:06
5

As already covered in List of acronyms in Fancy Table, creating a new template which happens to be similar to an existing one is entirely acceptable. Indeed, given the way the xtemplate code is set up, patching to alter interfaces is pretty tricky: to support the way concept is meant to work there are various internal structures one would have to alter.

At a conceptual level, the idea of a template here is to have a fixed 'designer' interface implementing some feature. There can be more than one template that do different things: one question of course is how far each template goes before one needs a different one. For a case where you need new parameters, either you need a new template or you need to get the original template author to extend it.

Whilst it's not officially supported, if you only want to alter the code part of a template that is doable as you can find the code in it's 'internal' location

\expandafter\patchcmd
  \csname\c__xtemplate_code_root_tl acro-list/table\endcname
  ...

It's worth noting here that xtemplate is experimental and has been used by the team to explore ways of providing a designer interface to parts of a document, but that it's not necessarily the 'final word'. Indeed, the team have concluded that some of the (deliberate) limitations of xtemplate mean that it's not the best long-term solution to the problem. The code does a poor job of dealing with context-dependent definitions, and as we can see here there's no (simple) inheritance available. As such, new ideas are being worked on and hopefully will emerge sooner rather than later!

  • The internal macro was what I was having trouble identifying; I figured at some point it came down to that. Looking forward to seeing how LaTeX3 evolves. – cslstr Jan 12 '17 at 3:01

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.