7

So, I basically want to do something like this:

\documentclass{article}
\usepackage{soul}
\begin{document}

\so{Hello}

\so{\input{key.tex}}

\end{document}

Now the first "so" works but the second does not. It does not find the file no matter how I specify the file location. Why does this not work and how could I fix it? Perhaps modifying the soul source code but what should I modify?

I would rather use the soul to do this because this is continuation from How to make overlaid text?.

1
  • A caveat: if the file 'key.tex' contains more than one paragraph and the content goes over a page break then page numbering can fail (see, for example, Bug with page numbers when using soul
    – mas
    Commented Sep 4, 2011 at 14:48

1 Answer 1

10

The soul package scans its argument and doesn't typeset it directly, therefore the content isn't inserted by \input. You need to read the file content manually and feed it to \so (or any other soul macro). This can be done easily using the catchfile package:

\documentclass{article}
\usepackage{catchfile}
\usepackage{soul}
\begin{document}

\CatchFileDef\filecontent{key.tex}{}
\expandafter\so\expandafter{\filecontent}

\end{document}

If you need this more often define a macro for this:

\newcommand{\soinput}[1]{%
    \begingroup
    \CatchFileDef\filecontent{#1}{}%
    \expandafter
    \endgroup
    \expandafter\so\expandafter{\filecontent}%
}
% ...
\soinput{key}

Note: The group is there to keep the assignment of \filecontent local and avoid any name clash if this macro is used somewhere else.

4
  • This works in the example perfectly but when added to the document I get an error: ! Argument of � has an extra }. for the \expandafter\so\expandafter{\filecontent} line. Any ideas?
    – user7630
    Commented Sep 4, 2011 at 17:26
  • Do you have special characters in the file name? Without more knowledge of your document it isn't easy to tell what is wrong. Try to only use \filecontent and see if the error disappears, so we know if it is the \so or the \filecontent. Commented Sep 4, 2011 at 17:33
  • It should not have any special characters and I can't find the � character anywhere. \expandafter\so\expandafter{test} works but everything else seems to fail. The filename actually is key.tex
    – user7630
    Commented Sep 4, 2011 at 17:57
  • In this case try to minimize your document and upload it somewhere so I can have a look on it. Commented Sep 4, 2011 at 21:13

You must log in to answer this question.

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