June 3, 2019 at 9:47 PM by Dr. Drang
When your audience is mostly Apple users, the evening after a WWDC keynote address is probably not the best time to post anything that isn’t about the day’s announcements. But I have one more thing to say about writing in LaTeX on the iPad.
A couple of days ago, I described a Drafts action and Shortcut that allow me to compile my LaTeX files on my Mac from my iPad. This is great if I’m writing in Drafts, but what if I’m using another editor? Specifically, what if I’m using Textastic, which has good integration with Dropbox and LaTeX syntax highlighting? If my report has complex formatting, that highlighting makes it nicer to write LaTeX in Textastic than in Drafts.1
Unfortunately, Textastic isn’t scriptable, so I can’t write an action for it the way I could with Drafts. But it does have a way of passing text to a Shortcut, so with a little trickery I can get around its limitations.
Here’s a file in Textastic with the commands needed to compile the LaTeX file over an SSH connection:
These are the same commands I used in the PDFLaTeX shortcut from Saturday’s post:
bash: export PATH=$PATH:/Library/TeX/texbin cd ~/Dropbox/projects/test/report latexmk -pdf -interaction=nonstopmode report
The only difference is that the directory (
~/Dropbox/projects/test/report) and file name (
latexmk doesn’t need the extension) are given explicitly instead of as dictionary look-ups. As you can see, they’re saved in a file named
build.sh, but the name doesn’t really matter. And although the commands will be run on a Macintosh, where
report.tex is saved,
build.sh doesn’t have to be saved there, certainly not in the same folder as the report. It can be a local file on your iPad or saved in the Textastic folder of iCloud. What’s important is that you can put it in a tab in Textastic, because we’re going to send its contents to a Shortcut.
And here’s the Shortcut:
All it does is log on to my Mac and run the commands that are passed into it as text. That text comes from
When I’m writing in Textastic, I keep the LaTeX source for the report in one tab and
build.sh in another. To compile my LaTeX file, I tab over to
build.sh and tap on the Sharing button in the top right corner. This brings down a menu with options for processing the text in the active file.
Most of them are Textastic-specific, but theoption hands the text off to the standard iPad share sheet.
From here, I tap
build.sh, and returns to Textastic. On my Mac is a newly built PDF of the report.
This is not nearly as convenient as pressing ⇧⌘P in Drafts—in fact, it requires five taps to compile and another to get back to the report file. But it is a way to write in Textastic without having to keep a Prompt connection to my Mac as an active app in Split Screen.
I’m hoping Greg Pierce adds a syntax highlighting engine to Drafts that understands LaTeX (and Python and Bash and …). I think it’s on his Someday list, but I don’t know how many other things are ahead of it. ↩