11

I have some LaTeX3 code that generates matrices and uses the hhline package internally. In LaTeX3 the ~ character is a special character, used for inserting spaces in strings, and using \c_tilde_str results in hhline ignoring the character and giving the warning:

Package hhline Warning: macro:->~ ignored in \hhline argument

I have tried various tricks such as defining

\cs_new_protected:Npn \__active_tilde { \~ }
\group_begin:
\char_set_active_eq:nN  {`~} \__active_tilde
\group_end:

and then using \__active_tilde but this does not work either.

Here is a minimal working example that exhibits my problem:

\documentclass{article}
\usepackage{hhline}

\usepackage{expl3}
\ExplSyntaxOn
\newcommand\mat{
\typeout{----------------------------------------}
  \begin{array}{cc} \hhline{~-} 1&2 \end{array}
\typeout{----------------------------------------}
  \begin{array}{cc} \hhline{\c_tilde_str-} 1&2 \end{array}
\typeout{----------------------------------------}
}
\ExplSyntaxOff

\begin{document}

$\mat$

\end{document}

This produces the output

enter image description here

with the overline over the 1's instead of the 2's. The log file contains the lines:

Package hhline Warning: macro:->~ ignored in \hhline argument
(hhline)                 on input line 24.

This shows that the first ~ is being ignored, as it should be since ~ is a space in expl code, and that the \c_tilde_str is not being recognised as a ~ by hhline.

[I know that the tabularray package gives other ways of doing this but it does not work in my real use-case because it does not support expansion in its key-value syntax -- and for the number of tables that I need to produce there may be other performance issues...]

1 Answer 1

11

Something like

\documentclass{article}
\usepackage{hhline}
\let\foo~
\usepackage{expl3}
\ExplSyntaxOn
\newcommand\mat{
\typeout{----------------------------------------}
  \begin{array}{cc} \hhline{\foo-} 1&2 \end{array}
\typeout{----------------------------------------}
  \begin{array}{cc} \hhline{\foo-} 1&2 \end{array}
\typeout{----------------------------------------}
}
\ExplSyntaxOff

\begin{document}

$\mat$

\end{document}
2
  • Thanks! I'm sure that I tried this... Oct 3 at 1:01
  • OK, as I am generating the \hhline parameter dynamically this needs \exp_args:Ne \hhline{\exp_not:N \foo\l_tmpa_tl}. Thanks again for pointing me in the right direction. Oct 3 at 2:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .