I am trying to input a text file to latex. However, this text file contains special symbols like % and & which causes issues. I do not want to import the file as verbatim, it should be imported like regular text with paragraph formatting and word wrap.
Asked
Active
Viewed 478 times
2
-
1Does https://tex.stackexchange.com/a/14344/15925 help? – Andrew Swann Jan 23 '19 at 08:47
-
1Or, if you are willing to use luaTeX https://tex.stackexchange.com/q/48425/5404 – Paul Stanley Jan 23 '19 at 08:49
-
@AndrewSwann It does, though that question is about verbatim, maybe we should copy the answer to here? – Cem Kalyoncu Jan 23 '19 at 08:50
1 Answers
6
Minimal approach:
\documentclass[]{article}
\newcommand\inputtextfile{}
\newcommand\redefinecharacter{}
\protected\def\redefinecharacter#1#2%
{%
\catcode`#1=13
\begingroup
\lccode`\~=`#1
\lowercase{\endgroup\def~{#2}}%
}
\protected\def\inputtextfile#1%
{%
\begingroup
\redefinecharacter{\\}{\textbackslash}%
\redefinecharacter{\{}{\{}%
\redefinecharacter{\}}{\}}%
\redefinecharacter{\$}{\$}%
\redefinecharacter{\&}{\&}%
\redefinecharacter{\#}{\#}%
\redefinecharacter{\^}{\^{}}%
\redefinecharacter{\_}{\_}%
\redefinecharacter{\%}{\%}%
\redefinecharacter{\~}{\textasciitilde}%
\input{#1}%
\endgroup
}
\begin{document}
The output of our file doesn't look too good, because we input something that
contains code as text :)
\inputtextfile{\jobname}
\end{document}
Ugly output:
Skillmon
- 60,462
