I was wondering what we could expect from our text editors when typesetting LaTeX documents. After all, in the beginning of the learning process, we need to somehow rely on code recipes and cookbooks. Andrew Stacey brilliantly discussed the keyboard layouts, which play a major role in our typesetting adventure (we need to focus on our documents, don’t we?). Now, think of this post more as a sidekick, a Robin to the TeX Dark Knight (holy macros, Batman!), a Dr. Watson to the rendering Sherlock Holmes, a Baldrick to the typesetting Blackadder. I want to share some ideas from me, a mere mortal, to you, traveller of the LaTeX land.
Don’t panic!
Editing LaTeX documents might not sound as an easy task, if you have too much stuff going on. The more complex document you have, the more trouble you might get into. A word of advice: when in dark times, your editor may help you. The Hitchhiker’s Guide to the Galaxy tells us what to do at first: Don’t panic!
Syntax highlighting
Believe me, syntax highlighting helps a lot, specially when you are insecure with your code block. I dare say it’s the greatest thing since sliced bread (nah, forget it). It might not be 100% accurate, but it does the job. A highlighted code gives character to your document editing. From this soulless document:
With the touch of syntax highlighting, it regains life:
It works, mate. It really does.
Code snippets
This one is a lifesaver. It’s like a magic spell. You press a bunch of keys plus the expansion key and voilà, the new code is inserted! What if you type, e.g. d + o + c + u + m + e + n + t + Tab and all of a sudden, the very code excerpt is expanded to:
Wow. From the original 31 keys, I just typed 9. And best of all, the cursor is where it should be, ready to register my real input. Classes, packages, document, items, you name it, virtually everything can be reduced to a code snippet.
In some cases, editors have code completion. It’s a similar concept, although I usually prefer code snippets.
Code snippets may be found in several editors, including one of my favorites, Vim. There is a great plugin called snipMate, created by Michael Sanders, which is suitable for the occasion. Click here to see snipMate in action.
Give code snippets or code completion a try. You won’t regret.
Formatters
Formatters are about coding styles, so it’s clearly a matter of taste. Nonetheless, these plugins make your code look better or at least less cluttered. Who can help you now? The formatter can! The formatter can ’cause he mixes it with love and makes the world taste good. Consider this code:
With the magic of the code formatter:
We just improved the code readability. Now I can see my elements as items of a tabular environment!
For Vim, there is a plugin called Tabular, by Matt Wozniski. Recently, Drew Neil from VimCasts.org made an excellent tutorial on how to use this amazing plugin.
Formatters probably won’t do what you want, but what you really need.
Voice commands
It’s time for a modern and audacious approach. This is probably not the most prolific way of typesetting documents, so please bear with me. This wacky idea might benefit us all, specially those in the beginning of the learning process.
My implementation
In the past, relying on voice recognition software was an arduous task. Nowadays, things are way easier, with several opensource toolkits freely available for developers. One of my favorites is CMU Sphinx, a voice recognition toolkit written in C and Java by the Carnegie Mellon University.
Since my intention is to show some aspects of voice commands, I came up with this simple finite state grammar. The modern voice recognition implementations now employ a medium vocabulary recognizer with semantic analysis framework.
In short, the voice recognition pattern will rely on this grammar. If I say old, the closest phonetic sound in my grammar is bold, so this word will be interpreted. As you can see, the recognition process will map phonemes according to the words defined in this grammar, no more no less. I warn you, this might cause you trouble when editing documents! There is a bonus video on this. It made me smile.
On the bright side, the implementation is very straightforward, since we have all possible words and sentences mapped:
I used a dirty trick (which I’m not proud of) to provide the code snippets. There’s a Robot
class in the Java Abstract Window Toolkit (java.awt
), which is used to “generate native system input events for the purposes of test automation, self-running demos, and other applications where control of the mouse and keyboard is needed”. Personally, I don’t like this procedure, but at least it works for my testing purposes.
Running the example
Apart for some bloopers, I got a working example on voice commands for LaTeX typesetting. As you can see, the word or sentence I say is recognized by a voice recognition component, which guesses what I said, gets the textual reference and triggers the correct method. So far, so good.
As mentioned before, the use of a finite state grammar might cause you trouble on the guessing part by the recognition component: enjoy my epic moments of fail. Please, also make fun of my accent.
Speak to me
It’s funny to talk with your LaTeX document. But instead of a textual feedback, how about an audio response? Don’t worry, it won’t be like HAL 9000 trying to kill you or not compiling your document. Consider this as a natural interaction.
One of my favorite speech synthesis systems is FreeTTS, built by the Speech Integration Group of Sun Microsystems Laboratories. It has an easy integration with CMU Sphinx, so everything works fine. Now your LaTeX assistant might be able to talk back to you. How does that sound (no pun intended)? For me, this idea gives a futuristic touch, and all we need to do is make sure we keep talking.
I think one of the questions for this unusual approach of typesetting is: what do I do with voice recognition and speech synthesis when editing my LaTeX document? Well, my idea is to use them during the LaTeX learning process. Let’s see how it should work.
May I take your order
It’s a cunning plan, actually. Consider the following scenario: John is a LaTeX newbie and has to write an article. A TeX distribution – TeX Live – is already up and ready. Let’s see how our interactive help system might help John.
So far, so good! The idea is to provide a simple yet concise feedback to the user. The system may also help John on inserting a figure:
This interaction may contribute to the LaTeX learning process. Of course, it might not be as beautiful as portrayed in here, but you probably got the idea.
Final thoughts
Typesetting LaTeX can be fun (or should I say funnier) if you use the right tools. Not that you really need them, but they reduce the stress on the attempt of keeping your code human-readable amongst the tons of macros, listings, TikZ codes, mathematical formulae and so forth.
I’d love to see a fully operational LaTeX assistant. Probably not the best thing ever, but one of the coolest, that’s for sure. I envision the day when I’ll say, “it’s me, LaTeX, do you copy?”, and a nice voice will echo through my speakers, “loud and clear”. Just keep the non sequitur thingy away from me.
Resources
- Editors on LaTeX: Charlie Tanksley’s series of posts on Vim and Seamus Bradley’s series of posts on emacs.
- Vim stuff: VimCasts.org, Vim Scripts
- Voice recogntion ans speech synthesis: CMU Sphinx, FreeTTS
It looks like some
(backslashes) have disappeared from your tabular code snippet.
Thanks, Seamus! I fixed them.
“It seems you want to insert a figure” reminds me of dear old Clippy. 😉
I was also reminded of that paper clip, and of the fact that there was once (may be still is) a version for
vim
! (Calledvigor
if memory serves me right.)I was also reminded of what happened once when my wife got a new computer. She was sat working at it one evening and called me over to ask about its strange behaviour. She was typing a document and it would keep changing the format, layout, and whatever. I sat down and had a look at it, and then to my wife’s amazement started telling it what to do. She had the speech recognition software switched on (it was on by default, I seem to remember). But what was strange was that neither of us had been talking earlier when it was doing all the strange behaviour. We figured out that it had been listening to the radio and interpreting what it heard as instructions.
So if you do use speech recognition to control your computer, make sure you turn the radio and TV off. Maybe the HAL9000 reference wasn’t so far fetched after all.