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?.

user7630
  • 105
  • 4

1 Answers1

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.

Martin Scharrer
  • 262,582
  • 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 Sep 04 '11 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. – Martin Scharrer Sep 04 '11 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 Sep 04 '11 at 17:57
  • In this case try to minimize your document and upload it somewhere so I can have a look on it. – Martin Scharrer Sep 04 '11 at 21:13