## Translating LaTex documents

I am trying to recapture Spanish after a long hiatus from four years of work in high school. As such, I decided that translating the KBD-Infinity instruction manuals would be educational as well as useful. A complete translation would take too much effort and could produce some strange results. I decided to use the resources of Google Translate (GT) combined with my reading knowledge of Spanish to remove any howlers. An instruction manual is an ideal candidate for machine translation. The original English text must be straightforward, with few idioms and no subtle turns of phrase.

LaTex is a popular markup language for typography. We use it for all our manuals. In comparison to word processors, it offers many advantages for maintaining documents. The source files are in text format that should be easy to upload to GT. Unfortunately, GT does not offer direct support for LaTex. In fact, it does some serious work mashing up the markup structure. Nonetheless, there are ways to compensate. In this article, I’ll describe an automated procedure that allows translation of an entire instruction manual, preserving all the visual structure of LaTex, in a half an hour or less.

First, a few words about using GT. For straightforward text, the translation is quite good. The service is free, and it is not necessary to be logged into Google. On the other hand, we have all come to know what “free” means on the Internet, so it would be wise not to upload documents with sensitive information. The main emphasis of GT is the translation of web pages. Accordingly, the service does a good job with the contents of an HTML pages, preserving the markup structure. Ironically, GT will not allow you to upload HTML documents directly. Supposedly, you can upload a variety of other document types (.doc, .docx, .odf, .pdf, .ppt, .pptx, .ps, .rtf,.xls, or .xlsx), but the performance is spotty. I found it refused to accept my .doc files for reasons unknown. It did accept PDF files, making a spare text-only translation with no visual elements. The best option is to use straight text (.txt).

There are some steps to prepare a Latex document for translation. First, GT will not accept a .tex file. It also refuses a .tex file with the suffix changed to .txt. Use a text editor to grab the content between \begin{document} and \end{document} and paste it in a .txt file. The second issue is that GT imposes an undocumented character limit. The general suspicion on the Internet is that the limit is 5000 characters. I found (as of this date) that GT would accept somewhat more than 20,000 characters. With larger documents, GT translates the first 20,000 characters and then fills out the remaining space with the original text, issuing no warning message. In consequence, input files larger than 20 kB must be split into parts. If you are concerned about issues of privacy or performance, it may not be useful to search for alternatives. Google has made GT open to websites and applications, so many translation services are simply front ends.

The translation process is simple.

1. Set the language preferences, click on Documents and browse for a file to upload,
2. The translated text appears in a text window. Press Ctrl-A then Ctrl-C to capture the output and paste it into a text file.

The aftermath is not so simple. In a long document, GT may introduce thousands of errors in the LaTex markup structures. For example, in a Spanish translation “\normalsize” becomes ” \ talla normal”. Note the addition of extra spaces, one of the primary problems. I realized that it would take days of hand labor to correct all the errors. My first thought was to create macros in my text editor, but this proved unworkable. In a typical LaTex document translation, there may be more than 70 different types of corrections to make. My ultimate solution was to write a utility code in which I could define any number of global replacements. This approach allowed almost instantaneous document correction.

Figure 1. ChangeIt interface.

Figure 1 shows the interface of my program ChangeIt. The critical concept is the ability to load custom template files that define multiple rules for global search and replace operations. Here’s an example of the template that evolved for my use in Spanish translations, SpanishTemplate.CTP:

* ChangeIt template
\ begin {$\begin{$
$\ end {$\end{\nueva pagina$\newpage$
$\Tabla de contenido$\tableofcontents\ textbf {$\textbf{$
$\ textit {$\textit{\ textsf {$\textsf{$
$\ texttt {$\texttt{\ textsl {$\textsl{$
$\Enorme$\Huge\Grande$\Large$
$\pequeña$\small$...$\ bigskip$\bigskip$
$enumerar$enumerate \ rightarrow $\rightarrow$
$\ footnote$\footnote ~ \ ref {$~\ref{$
$\ #$\#\ _$\_$

Footnotes

## Installing KBD-Infinity programs using Windows or macOS

Program installation is quite simple. In Windows, use the Download link to retrieve the executable installer. Typically, you would save the file in your Download folder or on the Desktop. In Windows Explorer or other file manager, double-click on the installer icon. The operating system may ask for permission to proceed. Windows 10 may issue the message:

Windows Defender SmartScreen prevented an unrecognized app from
starting. Running this app might put your PC at risk.

Despite the tone, it simply means that the program is not registered on the Microsoft Store. Click on More info to proceed. The program, instruction manual and examples are automatically copied to the correct locations. The installer also makes a shortcut on the Desktop. Double-click on the shortcut to run the program. Press F1 to open the instruction manual.

For the macOS, when you click the Download button a file ProgName.dmg is copied to your Download folder. Open Finder and navigate to the Applications folder. Then, open the Download folder and double click on ProgName.dmg. The compressed disk image is opened and a new Finder window shows the contents, a single folder with the name ProgName. To complete the installation, drag the program folder to the Applications folder. The program folder contains the app, the instruction manual and possibly other documents. After you run the program, the folder will also contain the configuration file which records program features and settings (e.g., the position of the program window).

An icon for the program may or may not appear in Launchpad. When you start the program, the Mac may issue a message like:

“MIDIDoctor” can’t be opened because it is from an unidentified developer. Your security preferences allow installation of only apps from the App Store and identified developers.

To continue, you will need to click System preferences/Security and privacy  Click OK in the previous warning dialog. The option to approve the program appears in the security dialog. Thereafter, the program runs like any other Mac software. To deinstall the package, simply drag the folder ProgName to the trash bin.

Two general usage tips for Mac users:

1) Finder does not include a button to go up one folder in the tree, which makes navigation problematic. For this function, use Command-UpArrow.

2) For compatibility with Windows, our programs make extensive use of mouse right-clicks. New Macs are supplied with a stylish monolith that appears to be a one-button mouse. Actually, it is a disguised two-button mouse with scroll wheel. To realize the full capabilities, go to System preference/Mouse. Uncheck Scroll direction: Natural, which is totally unnatural for Windows users. Check Secondary click/Click on right side to activate two-button performance. If this doesn’t work, note that you can plug any standard two-button mouse into the Mac to get full capabilities.

Footnotes

## New features in MiniMIDI Player

MiniMIDI Player (Figure 1), a component of the MIDI Utility Pack, is a compact program to play MIDI files. It provides a quick method to preview files and to determine their properties. We recently added some features to enhance its utility.

Figure 1. Screenshot of MiniMIDI Player

MiniMIDI Player can be used as a standard interactive program in a window. It can also be launched from the command line with the target file as the pass parameter. If MiniMIDI Player is defined as the Windows default program for the extension MID, it will launch when you double-click a MIDI file in Windows Explorer or other file manager. It also responds if you click on a link to MIDI file on the Internet in a browser. By default, in command-line mode the program closes after playing the file. If you want to repeat the play or load another file, click either the Play/Stop or Pause/Resume button. In this case, MiniMIDI Player exits command-line mode and stays active until you click the Exit button.

In addition to the MIDI file type and number of tracks, the program now displays the exact play duration in minutes and seconds including effects of tempo changes. Finally, we reduced the program footprint so it occupies minimal space on your desktop.

Footnotes