Friday, November 25, 2011

TeX Live 2009 on iOS





















Installing Tex Live 2009 on iOS (iPhone, iPad, iPod)


This guide is based on the
original guide at http://gamma-level.com/iphoneos/ports/texlive#tex-live-for-iphone
A huge thanks for this goes out to Aaron!


 


Jailbreak required. This guide
assumes you have a jailbroken device. I have
successfully installed it on a 16GB iPad 2 3G running
iOS 4.3.3.


This procedure does involve a few
command line steps, but Aaron has generously provided an easy package on Cydia.


Step 1: Add the
gamma-level.com repository to Cydia: http://gammalevel.com/cydia/


Step 2: Install mobileterminal from Cydia


Step 3: Start up mobileterminal and type <login>, which will prompt
you for a username <root> and password <alpine>


Once there, run the following
commands:


iphone:~ root# wget http://coredev.nl/cydia/coredev.pub


iphone:~ root# apt-key add
coredev.pub


iphone:~ root# echo 'deb
http://coredev.nl/cydia iphone main' > /etc/apt/sources.list.d/coredev.nl.list


iphone:~ root# apt-get
update


Step 4: Go back to Cydia and find TeX Live, which
should appear now.


The iPad
as a Productivity Tool


Texastic is a great app for TeX editing on the itunes store.
You can write up the document in there, use iFile
(also on Cydia) to move the tex
file from Texastic to somewhere easier to find with
terminal such as the Media folder, for example. Then you would use a terminal
program (I used iSSH) to compile the tex file as a pdf
file.


 


Instructions for iSSH (you could also ignore this and compile tex in mobileterminal)


I used iSSH,
a program on the iTunes store to log into the iPad
(it is basically the same as mobileterminal, except
it has better functionality). In order to use it like mobileterminal,
I recommend the following settings:


Add Configuration


description: loginroot


host: 127.0.0.1 (localhost address)


Login: root


Password: alpine (you can change
this by typing <passwd> in the terminal)


Alternate Configuration


description: loginmobile


host: 127.0.0.1


Login: mobile


Password: alpine


 


When in terminal, browse to the
folder that has the .tex file (use command <ls> to view the current directory and ensure that the tex file you wish to compile is there).


run


<latex
-output-file=pdf nameoffile.tex>


This should
compile the document as a PDF, assuming you wrote your latex document properly.





Friday, November 18, 2011

Applescript Facebook App for OS X and Safari

Facebook App for OS X and Safari

For those of us who are too lazy to open Safari and click on a favorite link for facebook, you can make an application with applescript, save it as an app, give it a relevant icon with Img2icns, and put a shortcut on your dock. Here is the code

--written in Snow Leopard 10.6.4
set skiList to {"http://www.facebook.com"}
set numURLs to (count skiList)
tell application "Safari"
activate
--open new window
make new document
-- open the URL
tell window 1
set URL of tab 1 to (item 1 of skiList)
repeat with i from 2 to (numURLs)
make new tab with properties {URL:item i of skiList}
end repeat
end tell
end tell

TeX Live for iOS

I just recently found this website http://gamma-level.com/iphoneos/ports/texlive#the_hard_way, where someone has created an iOS version of the TeX Live Package, a typical Xetex (or Latex) package with all the bells and whistles.

I am going to try installing this on the iPad 2. Hopefully it will allow me to compile XeteX on the iPad, making this a useful device for work, combined with the BibDesk reader app on itunes.

here is the original post:


TeX Live for iPhone

TeX Live is a common distribution of LaTeX, which is a system built around the TeX typesetting system by Donald Knuth (and others). It is well known for typesetting mathematics, such as {E} \psi(r) = - {\hbar^2 \over 2m} \nabla^2 \psi(r) + V(r) \psi(r), but it can also do almost any kind of typsetting you throw at it.

Installing via Cydia

The easiest way to install TeX Live for the iPhone is my Cydia repository. Be warned that TeX is huge. You will end up downloading 500 megabytes of data from my site, and after installation, it will take up a whole gigabyte or so. Make sure your device doesn’t go to sleep during installation.
To install TeX Live, you will need to add both my repo and the coredev.nl repo. Adding my repo is as simple as adding my URL in Cydia, but the coredev repo is a bit trickier. Install apt-get and wget in Cydia, then fire up a terminal (as root, and make sure Cydia is closed!) and run the following:
iphone:~ root# wget http://coredev.nl/cydia/coredev.pub
iphone:~ root# apt-key add coredev.pub
iphone:~ root# echo 'deb http://coredev.nl/cydia iphone main' > /etc/apt/sources.list.d/coredev.nl.list
iphone:~ root# apt-get update
Once you’ve added them, a section “TeX Live” should show up in Cydia, with a package “TeX Live” that you can install.

Compiling it Yourself

If you want to compile it yourself, you will need an on-iPhone development environment. Also you will need a copy of XZ Utils. You can either build it yourself or get it from my Cydia repository.
Luckily, the TeX Live source includes all the libraries it needs, so you don’t have many dependencies to go through. Using these libraries is easy, but they link statically so the final TeX binaries are much bigger. This works right now; my next goal is using system libraries instead.
The TeX Live build is long: make sure your device won’t go into sleep mode, or otherwise interrupt the build. TeX Live is mighty picky about build order, sometimes, so an interruption could be bad. It might not be, but it’s best not to risk it.
As always, if you have any questions, feel free to contact me.

The Easy Way

Here, I’m using the term “easy” lightly. There’s still a lot of steps, even with a patch file. Again, be sure your device won’t fall asleep on you!

Installing Build Tools

We need to add the coredev.nl APT repository so we can download perl. The following commands will add the source and its public key. Note that we use su to become root for a bit; the password asked for is root‘s.
iphone:~ mobile$ wget http://coredev.nl/cydia/coredev.pub
iphone:~ mobile$ su
iphone:/var/mobile root# apt-key add coredev.pub
iphone:/var/mobile root# echo 'deb http://coredev.nl/cydia iphone main' > /etc/apt/sources.list.d/coredev.nl.list
iphone:/var/mobile root# apt-get update
iphone:/var/mobile root# exit
Now, we can install the dependencies we need. perl is broken into a ton of small packages, so don’t be alarmed when APT tells you it’s installing about 100 things.
iphone:~ mobile$ sudo apt-get install perl bison flex m4
(We need to install m4 manually, even though it should be included as a dependency of either bison or flex.)
The iPhone OS limits the number of processes that a single user can run to some small number. Normally, this isn’t a problem, even when building things like Emacs. However, the TeX Live build system is massive, and you’ll quickly run up against this limit. I’ve written a little script that launches a subshell where this limit is much higher (64, in fact), so you can complete the TeX build.
#!/bin/bash
(whoami | grep --quiet root) || sudo $0
(whoami | grep --quiet root) || exit
sysctl -w kern.maxprocperuid=256 > /dev/null || exit
ulimit -u 64 > /dev/null || exit
echo Entering supermode...
sudo -i -u mobile
echo Leaving supermode...
To use, just save this as supermode in your home directory, and chmod +x supermode. Then, whenever you need the extra processes, use the command ~/supermode, type in your password if it asks, and a new shell will launch. To leave, just use exit. For the rest of this guide, I’ll assume you’re in “supermode”.

Fetching, Installing, and Building

Now we can fetch the TeX Live sources and the patch.
iphone:~ mobile$ wget ftp://tug.org/historic/systems/texlive/2009/texlive-20091107-source.tar.xz
iphone:~ mobile$ wget http://gammalevel.com/forever/texlive-20091107-iPad.patch
Make sure the XZ Utils are installed, then extract the sources and apply the patch. Try to free up as much memory as possible before this step; the extraction can take a while, and the file is large.
iphone:~ mobile$ xzcat texlive-20091107-source.tar.xz | tar xv
iphone:~ mobile$ cd texlive-20091107-source
iphone:~/texlive-20091107-source mobile$ patch -p1 < ../texlive-20091107-iPad.patch
Now, we’ll create a seperate build directory, and configure TeX Live. Make sure to include every part of this massive list of configure options, and note that pwd is inside back-ticks (the un-shifted version of ~ on most keyboards). In fact, it’d probably be best if you just copy and paste that last command…
iphone:~/texlive-20091107-source mobile$ mkdir ../texlive-build
iphone:~/texlive-20091107-source mobile$ cd ../texlive-build
iphone:~/texlive-build mobile$ ../texlive-20091107-source/configure --datadir=`pwd` --prefix=/usr --with-tex-banner="TeX Live 2009/iPhone OS [gammalevel.com]" --disable-xetex --disable-shared --disable-missing --disable-largefile --disable-threads --without-x --disable-native-texlive-build --disable-multiplatform --disable-xdvipdfmx
Once TeX Live is done configuring itself, we’re ready to build and install. This part can take a while; go get some coffee.
iphone:~/texlive-build mobile$ make texmf=${TEXMF_PATH:-/usr/share/texmf}
iphone:~/texlive-build mobile$ sudo make texmf=${TEXMF_PATH:-/usr/share/texmf} install-strip
Congratulations! You’ve just installed TeX Live for iPhone! However, it’s not usable yet…

Installing the texmf Tree

First of all, TeX Live just installed a useless baby texmf tree already, and into the wrong place no less, so let’s remove that:
iphone:~/texlive-build mobile$ cd ../
iphone:~ mobile$ sudo rm -rf /usr/texmf /usr/texmf-dist
Now, you need to download, extract, and install the texmf tree. This file is gigantic: around 900MB! This part will probably take even longer than the compile, so if you want, you could download it on a computer, then move it to your device.
iphone:~ mobile$ wget ftp://tug.org/historic/systems/texlive/2009/texlive-20091107-texmf.tar.xz
(If the download is cancelled somehow, just run the wget command again with -c to ensure it will continue downloading where it left off.)
At this point, you really should make sure the file is correct:
iphone:~ mobile$ sha256sum texlive-20091107-texmf.tar.xz
63e38a218c04e28081e12b4f48969a7e25cf5f81a8c4807aae815a49b575ae5d  texlive-20091107-texmf.tar.xz
Now we can continue with extraction and installation:
iphone:~ mobile$ xzcat texlive-20091107-texmf.tar.xz | tar xv
iphone:~ mobile$ sudo mv texlive-20091107-texmf/texmf* /usr/share/

Finishing Up

The texmf.cnf we installed has the wrong paths, so we’ll replace it:
iphone:~ mobile$ wget http://gammalevel.com/forever/texlive-20091107-texmf.cnf
iphone:~ mobile$ sudo mv texlive-20091107-texmf.cnf /usr/share/texmf/web2c/texmf.cnf
Now, we need to tell TeX Live to reconfigure itself after the install:
iphone:~ mobile$ sudo mktexlsr
iphone:~ mobile$ sudo texlinks
iphone:~ mobile$ sudo texconfig-sys init
(The last command will exit with an error, complaining about failed format builds for xetex: these are normal, because we disabled it! If there’s any other errors, though, those are real problems.)
Congratulations! You have just finished installing TeX Live! To configure your new system (for example, to set the default paper size), use this command (though honestly, it’s never worked for me):
iphone:~ mobile$ texconfig

The Hard Way

I’m still backtracking through what I did to find out all these patches and configure options, but when I figure it all out again, I’ll put why I made those changes here.

Created July 11, 2011, 10:44 p.m.; last modified Oct. 25, 2011, 7:27 p.m. (history).