I got a LaTeX project that has been exported (downloaded) from an ShareLaTeX Online installation. Seems that it stored all Tex files as US-ASCII according to what I see on MacOS using the following command in the terminal:
file -I myfile.tex
Which results in:
myfile.tex: text/x-tex; charset=us-ascii
The original error is:
myfile.tex:8: Undefined control sequence. …\numberline {\thechapter }Vortr\UTF{00E4}ge}{\thepage }} l.8 \chapter{Vortr\UTF{00E4}ge}
And the LaTeX source is (where the \ got copied and pasted here as a ¥ symbol). The original file can be download here.
\documentclass[12pt,a4paper,ngerman,onecolumn]{book}
\usepackage[ngerman,english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\begin{document}
\chapter{Vorträge}
\end{document}
The question is, can I fix this somehow? I know that UTF-8 is the better choice. But the LaTeX project consists of many files that are all in the US-ASCII encoding.
Best Answer
The exported file has replaced the UTF-8 characters by macro calls
\UTF{...}
with the hexadecimal Unicode code point as argument. The macro could be defined in TeX, but this will not work in all circumstances (verbatim text, ...). Therefore, the best approach is to write a script/program to convert the macro calls back to the UTF-8 encoded Unicode characters.Here a simple script
sharelatex_recode.py
for Python 3. It takes the file as argument and updates the file if necessary:The problematic line
becomes
It is also possible to convert all
.tex
files recursively, example forbash
:Unicode characters outside the BMP (Basic Multilingual Plane) are not supported by the script, because I do not know, what the export of ShareLaTeX to US ASCII does in this case.