Expectation Symbol in LaTeX

After looking for a built-in expectation symbol in LaTeX, and coming up with none, I’ve defined one. Just add:

% Expectation symbol
DeclareMathOperator*{E}{mathbb{E}}

to your LaTeX preamble, and you’re done. You’ll also need to add usepackage{amsmath}, or in LyX, tick “Use AMS math package” under Document->Settings->Math Options.

Using the starred version of DeclareMathOperator makes sure subscripts go beneath the symbol in display mode.

LaTeX for TiddlyWiki – A MathJax Plugin

Update: The MathJax Plugin for TiddlyWiki has a new home: https://github.com/guyru/tiddlywiki-mathjax
Some time ago, I came across MathJax, a nifty, JavaScript-based engine for displaying TeX and LaTeX equations. It works by “translating” the equation to MathML or HTML+CSS, so it works on all modern browsers. The result isn’t a raster image, like in most LaTeX solutions (e.g., MediaWiki), so it scales with the text around it. Furthermore, it’s quite easy to integrate, as it doesn’t require any real installation, and you could always use MathJax’s own CDN, which makes things even simpler.

TiddlyWiki with the MathJaxPlugin
A tiddler with LaTeX equations.

Continue reading LaTeX for TiddlyWiki – A MathJax Plugin

lyxframeend Undefined when Using Beamer with LyX

I’m using LyX for the first time with Beamer. Making the title page was smooth. But when I tried adding a new frame (using BeginFrame), I was confronted with the following error

 lyxframeend
                 {}lyxframe{Outline}
The control sequence at the end of the top line
of your error message was never def'ed. If you have
misspelled it (e.g., `hobx'), type `I' and the correct
spelling (e.g., `Ihbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

After comparing my document to example (working) Beamer documents, I’ve found out that you must have an EndFrame command after your last frame. Too bad it wasn’t documented anywhere I looked, as this little thing drove me crazy.

Emulating Kav-Mafrid (em-dash) for the David Font

The David font that is used in Culmus-LaTeX lacks support for Kav-Mafrid, the ligature that is created by two consecutive dashes, --. Because the regular Hebrew dash, Maqaf, is positioned near the top of the line, one can’t use it instead of the Kav-Mafrid and expect a graphically pleasant result (while Kav-Mafrid can replace Maqaf and the text would still look ok). To make things even more problematic, this ligature is supported by Culmus-LaTeX’s default font, Frank Ruehl, which means one can’t easily switch fonts without hurting the layout.
Continue reading Emulating Kav-Mafrid (em-dash) for the David Font

Getting Hyperref to Work with Hebrew (in XeTeX)

The hyperref package is notorious for causing problems with RTL text, which unfortunately includes Hebrew. In this post, I present some preliminary workarounds that enable the user to use the hyperref package with Hebrew and possibly other RTL languages. The solution requires XeTeX, which is available in TeXLive. I had no success yet porting the workaround to pdfTeX, which is more popular.
Continue reading Getting Hyperref to Work with Hebrew (in XeTeX)

Displaying Non-Builtin Math Macros in LyX

I believe LyX is a great tool for writing LaTeX documents. It makes writing formulas very easy, and it allows you to see the formula as you are writing, as opposed to seeing only LaTeX code. However, LyX doesn’t support every LaTeX package and the macros it defines. Sure, it doesn’t stop you from using these macros in your formulas, but they don’t display nicely; you see the name of the macro instead of a schematic preview.

While LyX doesn’t support many of the great packages out there, like mathtools (which I really hope it will someday), you can add some support to your documents. At the beginning of the document, insert a comment via Insert->Note->Comment. Inside the newly created comment, insert a math macro via Insert->Math->Macro. In the name part, put the name of the command you want to add support for. In the second box (captioned LyX), use existing LyX commands to mimic how the macro will look. For example, this is what it looks like for the coloneqq macro (from the great mathtools package):
math-macro

After adding the math macro in the comment, when you use the macro inside formulas, it will display nicely:
math-macro2

A little explanation of how things work: when you define a math macro in LyX, LyX does two things:

  1. Inserts LaTeX code to create the macro.
  2. Displays the macro nicely when editing the document.

While the latter is desirable, the former is problematic. If LyX inserts LaTeX code to define the existing macro, it will cause errors. So when you put the LyX macro in the comment environment, the code LyX generates gets ignored, and only the second, desirable, outcome is achieved.

Drawing Finite Automata and State Machines

I had to draw a couple of Finite Automata and Turing Machines for some university assignments. Usually, I would have done it using Inkscape (as it is my favorite tool for creating figures for my LaTeX documents), but doing it manually is pretty tedious work. Inkscape’s diagram tool is currently subpar, so everything has to be done by hand. It’s OK if you need to draw one State Machine once in a while, but it’s not suitable for larger quantities. I’ve also tried using Dia, but it also required lots of manual tweaking and tuning.

To my surprise, Graphviz (and especially the dot utility) turned out to be the (almost) perfect tool for the job. It lets you describe the graph in a simple text-based way, and it handles the graph layout by itself. This is somewhat like LaTeX, but for graphs (you concentrate on content, not layout).

My Finite Automata needed no manual tweaking and resulted in very nice graphs. For more complicated State Machines, it’s sometimes necessary to do some manual tuning. The commands I found most useful to tweak the graph were:

  • Grouping nodes to be on the same level – { rank="same"; "q1"; "q2"; "q3"}. The other options for rank can affect how the group is positioned relative to the other nodes in the graph (source, above all, sink below all).
  • Adding weight to edges – q1 -> q2 [weight="10"]. This affects the cost of stretching the edge. The higher the weight, the straighter the edges will be.
  • Adding invisible edges – q1 -> q3 [style="invis"]. This allowed me to control the order of the nodes in the same rank (height).

Last but not least, Graphviz can generate graphs in a variety of formats, including eps, pdf, and svg (which allows post-processing with Inkscape).

LaTeX Error: Command \textquotedbl unavailable in encoding HE8

I was testing today the SVN versions of LyX 1.6.0 and 1.5.7. Due to a change in the way the double quotation mark (“) is handled, adding it to Hebrew text resulted in the following LaTeX error:

LaTeX Error: Command textquotedbl unavailable in encoding HE8

Continue reading LaTeX Error: Command \textquotedbl unavailable in encoding HE8

Equality-at and Relation-at LaTeX Macros

These are two useful LaTeX macros for creating equality-at and, more generally, relation-at signs. These macros depend on the mathtools package. As with all other macros, you should add them to your preamble in order to use them.

The general macro is relat. It takes two arguments: the relation and an expression where the relation takes place (the “at”). The equality-at macro, eqat, is a specific case of relat. I’ve created it because it is commonly used and only requires passing the “at” argument.
Continue reading Equality-at and Relation-at LaTeX Macros