2

I am using the soul package to produce "distributed" text. That is, text that is automatically spaced such that it fills the entire line. This works great, but now what I want to do is use a \newcommand within this context, so I can remove redundancy from my source files.

\documentclass{article}

\usepackage{soul}
\sodef\distribute{}{0pt plus 1fil}{0pt plus 2fil}{0pt}

\newcommand{\greeting}{Hello, World!}

\begin{document}
  \distribute{\greeting}
\end{document}

If you replace \greeting in \distribute with literal text, then it works fine. However, with \greeting it results in a "Reconstruction failed" error. The soul documentation says this is due to "grouping hyphenable material" or "leaking font switches". The former can be resolved with an \mbox, but then that prevents the letter-spacing from happening; the latter doesn't mean much to me, but I don't think it applies here.

Is there a way of getting line-width distributed letter-spacing containing variables?


A similar question is answered with, "Use microtype." This package, however, looks pretty low-level and I'm not sure where to begin to achieve my goal.

0

You can use the expl3 construct \exp_args, which expands arguments before a macro is executed. See Expanding arguments before macro call for example.

MWE:

\documentclass{article}
\usepackage{xparse}
\usepackage{soul}
\sodef\distribute{}{0pt plus 1fil}{0pt plus 2fil}{0pt}

\newcommand{\greeting}{Hello, World!}

\ExplSyntaxOn
\NewDocumentCommand{\expdistribute}{m}{%
\exp_args:No\distribute{#1}%
}
\ExplSyntaxOff

\begin{document}
\expdistribute{\greeting}

\distribute{Hello, World!}

\distribute{All your base are belong to us}
\end{document}

Result:

enter image description here

1
  • Thanks -- this works in my minimal example, but it doesn't seem to work in my actual document, which is a bit more complicated... Never mind; I can live with redundancy :) Jul 8 at 18:59

This site is temporarily in read only mode and not accepting new answers.

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