# How can I translate to English a TeX document without losing compilability?

Is there any way I can translate comments and non-commands from a different language to English ?

I tried :

2. Using http://translate.google.com/ to translate File pasted as text

Obviously will not compile

3. Using http://translate.google.com/ to translate File drag-and-drop

I got the following result:

Sorry, the page you requested contains a file type (application/octet-stream) we are unable to translate.

• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Dror Dec 11 '13 at 11:51
• Hi! A similar question has appeared before: Translate ONLY italian text, inside LaTeX sources, into english. It was conlcuded that this type of question is off-topic. I'm not claiming that this question should be consider off-topic; I'm just putting here the relevant information. – yo' Dec 11 '13 at 12:08
• Maybe you can take a look on app.uio.no/ifi/texcount/online.php . This tools has algorithms to find "real text" and comments in your TeX code. Haven't looked on the source code, but maybe there is some nice code to extract your text for translation. (Just an idea for hacking that...) – LaRiFaRi Dec 11 '13 at 12:41
• detex strips out a lot of commands etc. but it probably still leaves maths. It might be a good start, though. – cfr Dec 20 '13 at 3:50
• a solution could be with regular expression and e.g. perl, so you parse for comments (easy) and other text (more difficult?), remember the position of the single pieces of text in the whole file and write the text linewise in a file. Translate that file. Read it in again and put the text back in the document at stored places. – Faekynn Jun 22 '14 at 15:13

Try this:

1. 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."

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

1. Translate text.

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