This is a little tutorial on how to embed MathJax in Empathy's and Adium's chat windows, making it possible to use LaTeX formulas in chats without resorting to plugins or calling external scripts.
I tested this change only in Empathy 3.6 on Ubuntu 12.10 with the "Ubuntu" message style, and other configurations may require different changes. Do not forget to make a backup of the files you are going to modify.
TO DO: call "Typeset" on the new fragment only, attach a screenshot (Nvidia's fault).
Embedding MathJax into an AdiumMessageStyle
Empathy and Adium use HTML+Javascript templates to display the content of the chat windows. Since they actually use Gecko and Webkit, it is possible to embed pretty much any code you like.
MathJax is a handy Javascript library that converts LaTeX formulas inside $$ ... $$
and \[ ... \]
into MathML or images, depending on the configuration. In order to enable the MathJax library inside an Empathy chat window it is enough to do the following.
Install the MathJax library somewhere (either via your package manager or downloading it), copy/extract your favourite message style into the folder ~/.local/share/adium/message-styles/
and modify its Template.html
in the following way:
- add the line
<script type="text/javascript" src="/~mantova/io/%3Cstrong%3E%5Blocation%20of%20MathJax%5D%3C/strong%3E/MathJax.js?config=default"></script>
just before the first<script>
tag; this will import MathJax in the message style; - add the line
MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
inside the body of theappendMessage
, near the end of the function, after the new message has been added to the page but before any other formatting commands (e.g., a call toalignChat
); this tells MathJax to look for new LaTeX code every time a new message is displayed on the screen; - repeat the last step inside the body of the function
appendMessageNext
, unless the function callsappendMessage
.
I suggest to modify the file Info.plist
as well appending a "+ MathJax" to the style name.
Instructions for Ubuntu 12.10
If you use Ubuntu 12.10 and the "Ubuntu" message style in Empathy, you can use the attached patch.
- Download the attached
ubuntu-message-style+mathjax.patch
- Install
libjs-mathjax
:sudo apt-get install libjs-mathjax
- Create a directory in your home folder to host the new message style:
mkdir -p ~/.local/share/adium/message-styles
- Copy the default Ubuntu message style to your home folder:
cp -r /usr/share/adium/message-styles/ubuntu.AdiumMessageStyle ~/.local/share/adium/message-styles/ubuntu+mathjax.AdiumMessageStyle
- Go inside the directory of the new message style:
cd ~/.local/share/adium/message-styles/ubuntu+mathjax.AdiumMessageStyle
- Apply the patch:
patch -p1 < [location of the downloaded patch]
- Choose the new theme "Ubuntu + MathJax" in Empathy's preferences.
- Open a new chat tab and write some LaTeX code inside
$$ ... $$
or\[ ... \]
- Enjoy!