How can I translate to English a TeX document without losing compilability?
Try this:
Save the file with a
.txt
extension. This will avoid the error "Sorry, the page you requested contains a file type (application/octet-stream) we are unable to translate."Change all backslashes using your editor to
==zz
. This results to words that Google cannot translate and hence it leaves as is. This works well for single commands.
Use the same strategy for any other items you do not want Google to translate. For example you can search and replace all {
with BACKSLASHSH
. This way you will not get any unwanted spaces. Just use words or mixtures of words and numbers that Google will not have a translation. For example it will translate figure
but not FIGORE
.
Translate text.
Search and replace again with your editor all
==zz
to backslashes and other strings you have protected.
If you familiar with coding in a language such as Perl, Python or Lua you can fence the commands in a more robust way, by providing a small script to do all the search and replace. For example you could change all:
\begin{figure}[htbp]
to a hash key such as 12345678
to protect it from translation, and then reverse it back again once you have the translation.
Sadly Google does not provide a free web API any longer, otherwise you could have done all this automatically via LuaTeX and the socket library or similar.
Here is a tool gtexfix
which I wrote which does the replacements of LaTeX commands and math formulas by tokens automatically. It helps to translate safely .tex
documents with Google Translate without breaking the LaTeX.
You can use https://www.deepl.com You can give it tex file. DeepL keeps formating and markup (although, not always).