A while ago I stumbled upon the semantic package --- its 'math ligatures' feature in particular --- and the whole way in which I write math-code in LaTeX changed.

Instead of

  \sem{\sigma}_s^x \quad \defeq \quad
      { \sigma' \subseteq \Sigma }
      { \exists s' \in S: \config{s, \sigma} \longrightarrow \cdots \longrightarrow
        \config{s', \sigma'} \land x \in \sigma' }

(already cleaned up with specific-purpose macros) I can now write

  [[ \sigma ]]_s^x  =def
    { \sigma' <=set \Sigma }
    { .E. s' .in. S: <( s, \sigma )> --> ... --> <( s', \sigma' )> .and. x .in. \sigma' }

and get an identical result (MWE upon request).

Question: I was wondering if there are other packages like that: packages that make your (La)TeX code easier to read. (Perhaps even a replacement for semantic itself because, truth be told, that package is somewhat old and a bit buggy here and there.)

Edit: Please note, I'm interested in any package meant to enhance source code readability. It doesn't have to be anything like my example.

Several other questions exist concerning code readability, but none of them focus on packages.

  • 1
    Most of the tree drawing packages, the common tikz-qtree and the recent forest use such code parsing techniques. You can check them out for inspiration if you are inclined to write something along those lines.
    – percusse
    Jan 31, 2013 at 21:24
  • Maybe it gets better if one gets used to it or has to write lots of formulae but I don't see the advantage. Maybe I also have written enough math code that I don't have problems reading the "normal" code. Jan 31, 2013 at 21:26
  • 2
    On the script side of things, code-prettifier latexindent.plx could help make source code more readable.
    – Werner
    Jan 31, 2013 at 21:26
  • I use a lot of eRuby in my latex documents. For example, I can do a figure using something like <% fig('pendulum','A pendulum looks like this.',{'width'=>'fullpage','sidecaption'=>true,'sidepos'=>'b'}) %>, which might generate something like \fullpagewidthfig{pendulum}{A pendulum looks like this.}{}{}{1}{}{b}. The ruby version is more readable because ruby, unlike tex, was designed to be a general-purpose programming language. The options inside the {...} can have defaults, and I can easily add new options without breaking old code.
    – user6853
    Jan 31, 2013 at 22:06
  • The code you give a sample of is for a very specialized task; I don't think it's particularly readable, but it's a question of being used to it or not. For general text I don't see how something of that kind could be useful.
    – egreg
    Jan 31, 2013 at 22:45

2 Answers 2


Using unicode for math improves readability by a huge factor:

\SEM σ_s^x ≝ 
      { σ' ⊆ Σ } 
      { ∃s' ∈ S: \CONFIG {s, σ} ⇒ \cdots ⇒ \CONFIG {s', σ'} ∧ x ∈ σ'}

If you editor supports keyboard shortcuts (e.g., imap or IMAP in vim, or `a -> α type mappings in emacs), then you typing unicode symbols is not difficult at all. (There was even a vim plugin floating around that converted LaTeX math to Unicode math whenever you saved a file).

I mostly use ConTeXt, which supports Unicode (and Unicode math) out of the box. For LaTeX, you need to load the unicode-math package.

  • So is there a way to enter the characters as LaTeX commands (\longrightarrow) but have the editor automatically replace them with Unicode equivalents ()?
    – Superbest
    Jan 28, 2014 at 5:51
  • @Superbest: that is an editor feature. In vim, i can type CTRL-K => to get the unicode glyph. Similar digraphs exist for other common unicode symbols as well
    – Aditya
    Jan 28, 2014 at 13:42

I find the ragged and irregular length source lines in your source samples very distracting.

I find it it easier to follow the code if you remove such distractions.

Fjfi71PAVVFjbigskipRPWGAUU71727374 75,76Fjpar71727375Djifx
RrhC?yLRurtKFeLPFovPgaTLtReRomL;PABB71 72,73:Fjif.73.jelse
B73:jfiXF71PU71 72,73:PWs;AMM71F71diPAJJFRdriPAQQFRsreLPAI
I71Fo71dPA!!FRgiePBt'el@ lTLqdrYmu.Q.,Ke;vz vzLqpip.Q.,tz;
;Lql.IrsZ.eap,qn.i. i.eLlMaesLdRcna,;!;h htLqm.MRasZ.ilk,%
s$;z zLqs'.ansZ.Ymi,/sx ;LYegseZRyal,@i;@ TLRlogdLrDsW,@;G
LcYlaDLbJsW,SWXJW ree @rzchLhzsW,;WERcesInW qt.'oL.Rtrul;e
doTsW,Wk;Rri@stW aHAHHFndZPpqar.tridgeLinZpe.LtYer.W,:jbye
  • 3
    Haha, I very nice. Jan 31, 2013 at 22:44
  • :-) --- +1 if you wrote that yourself. ;-)
    – mhelvens
    Feb 1, 2013 at 8:56
  • @mhelvens (it's rather old: look for xii on ctan or tugboat) Feb 1, 2013 at 9:35
  • I think you've got an typo in "1l7" - that should be "1I7". Feb 1, 2013 at 12:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .