Wikipedia: Minification is (also minimisation or minimization), in computer programming languages and especially JavaScript, is the process of removing all unnecessary characters from source code without changing its functionality. These unnecessary characters usually include white space characters, new line characters, comments, and sometimes block delimiters, which are used to add readability to the code but are not required for it to execute.

Minification is ubiquitous in web-development, especially for Javascript and CSS. I was just wondering whether the same principle might be valuable for (La)TeX package files.

My first instinct was 'no', and I'm still leaning in that direction. JS / CSS files benefit from minification because it speeds up their downloads. The speedup in parsing may be negligible.

Still, TeX files, like Javascript files, are interpreted again and again. I figure a small speedup might add up over time. And Javascript files are cached, so the download speedup isn't that great over the long term. Also, a LaTeX minifier could perform some nifty tricks, especially if it was allowed to assume that csnames containing a @ or starting with __ are never referred to outside of the file.

So I think it's a question worth asking. Has anyone ever tried anything like this?

  • 2
    I'm no expert on web development but my understanding is that minification is mainly used for web contents and is meant to reduce the size of files that are transferred from server to client. Since TeX & friends involves no data transfer (aside perhaps in the case of Writelatex, etc.), the only potential advantage of minifying TeX code would be storage efficiency, to the obvious detriment of code readability. Count me out. – jub0bs Oct 17 '13 at 21:23
  • 3
    In TeX spaces (or end-of-lines) are significant in the vast majority of cases. Comments are thrown out during tokenization and this ‘throw out’ operation takes a negligible amount of time, compared to macro expansion and command execution. – egreg Oct 17 '13 at 21:59
  • 1
    @egreg Your comment is cruelly missing a comma after the second word :p – jub0bs Oct 17 '13 at 22:08
  • 1
    @mhelvens (Trying to write all necessary commas.) I can't understand what you mean; package loading could benefit from this process (not much, I believe), but I'd be scared by a minifier that removes a newline in situations such as \somecounter=3<newline>\cs, because this might lead to disasters. – egreg Oct 17 '13 at 22:15
  • 1
    Because of the way TeX works even sophisticated "syntactic" minification will probably brake any non-trivial package. However, to some extent, I think format files are basically the TeX version of minification. – Bordaigorl Oct 17 '13 at 22:36

It's possible, but unlikely (and not worth the effort). TeX on todays machines is incredibly fast (remember: compiling the TeXbook took hours in 1982, but now takes only seconds), so your typical document will compile in less than five minutes. Most of this time is not taken by the "parser", but most likely I/O and calculations done by macros. You gain some speed by creating a format file, though (which is some kind of minification); see also .

  • While this is all true, I sometimes compile my document constantly while writing. Sometimes I have to wait for specific spacing / formatting results before I can move on. 10 seconds can feel like an eternity. :-) --- Nonetheless, I think there is a consensus on what I already suspected: it's probably not worth the effort. --- If you'd like to integrate the comments above into your answer I'll accept. – mhelvens Oct 18 '13 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.