# [Tex/LaTex] make LuaLaTeX use \input files that are ANSI encoded

input-encodingsluatexunicode

I include/\input automatically generated files (tables generated by Stata) into my main document. I would like to compile that document with LuaLaTeX. Unfortunately the generated files are ANSI-encoded (Stata does not support unicode). LuaLaTeX thus throws a "String contains an invalid utf-8 sequence" error at me. At the moment, the problem is only a single character, namely ¤ (U00A4 according to Windows Character Map). With XeLaTeX or without the character the document compiles fine.

I would prefer to not search and replace the character (with e.g. \textcurrency, though something that works in math-mode as well would be preferred), since it involves many included files that change often. For the same reason I would prefer to not convert the encoding of the included files by hand. I would also prefer a more robust solution, i.e. not only for single characters.

So is there a way to make LuaLaTeX use included files that are ANSI encoded, comparable to using \inputencoding with pdflatex?

Alternatively, is it possible to automatically search and replace when compiling?

Here is a MWE:

\documentclass{article}
\usepackage[vargreek-shape=unicode]{unicode-math} %
\defaultfontfeatures{Renderer=Basic,Scale=MatchLowercase, Ligatures={TeX}}
\setmainfont{Cambria}
\setmathfont{Cambria Math}

\begin{document}

A currency symbol in the main document: ¤

\input{input.tex}

\end{document}


input.tex just has one line, but is ANSI-encoded.

A currency symbol in the included document: ¤


To tell LuaTeX to accept other encodings than UTF8 you need an additional package. Similar to the inputenc for LaTeX luainputenc provides the necessary commands for LuaTeX. The basic syntax is just \usepackage[<encoding>]{luainputenc}. Where the most commonly used encodings are latin1 and cp1252. The slightly changed example compiles without errors:

\documentclass{article}

\usepackage[latin1]{luainputenc}

\usepackage[vargreek-shape=unicode]{unicode-math} %
\defaultfontfeatures{Renderer=Basic,Scale=MatchLowercase, Ligatures={TeX}}
\setmainfont{Cambria}
\setmathfont{Cambria Math}

\begin{document}

A currency symbol in the main document: ¤

\input{input.tex}

\end{document}


Alternatively you could use tools such as iconv to automatically convert the file.