Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
LaTeX Tooling Guide (norswap.com)
167 points by norswap on March 29, 2017 | hide | past | favorite | 63 comments


What should be step 1: it's 2017, you want XeLaTeX or LuaTeX, both capable of native unicode handling, using fonts by name, etc. Traditional LaTeX (and I use "traditional" with scorn as we've had XeLaTeX for almost 15 years now), relying on the ancient pdftex engine, might be "easier to google" (let alone remember), but is also not an acceptable thing to recommend to people if all they want to do is control their typesetting.

It's like talking about how hard it is to work with browsers and then telling people the best way to set up IE8, instead of using a modern browser.

Of course it's still you in the typesetting driving seat, it's never going to be as easy as Word, but I'm writing a novella in XeLaTeX right now, not even maths papers, and it's almost child's play to make it do what I want with minimal effort. My entire "complicated setup" is five lines plus one line that's me being completely unreasonable, with XeTeX going "sure, be that way":

  \documentclass[11pt, oneside]{book}
  \usepackage{tocloft}
  \usepackage{fancyhdr}
  \pagestyle{plain}
  \usepackage[b5paper, bindingoffset=0mm, inner=23mm, outer=23mm, top=21mm, bottom=24mm]{geometry}
  \input{quotation-rules.tex}
And that's it, the rest of the document is basically just a giant text file of paragraph after paragraph of normal text, using normal as-per-unicode accented letters saved in UTF8. The doc's certainly interspersed with \part{} and \chapter{} markers because that's how a story works, but there is nothing I couldn't explain to my mom in there: I'm writing a "book" with a table of content, a reasonable looking page header but otherwise plain styling, with some explicit page dimensions (which is no different from using Word for a specific page size).

(the only unreasonable demand being that "\input" line, which imports a set of rules for using "Palatino Linotype" as main font, but then pulling the punctuation glyphs from "Sylfaen". So stuff like full stops, apostrophes, commas, double quotes, etc. And even for something seemingly as complex as that, is just a few more lines using modern XeLaTeX)


Besides native UTF support and fonts what advantages do the XeLaTeX and LuaTeX ecosystems offer over LaTeX?

You mention writing a novella as your use case, but I don't think that's a particularly difficult task for a typesetting engine. If you found typesetting a textbook with "rich" margins, annotations, and figures significantnly easier I would be more inclined to learn about alternatives.

With LaTeX I can transform my research papers to comply with a publisher's template in a few lines of code. Sure there are some annoyances such as compile compile bibtex compile, but the ecosystem is mature enough that most of these are well handled.


They still support the LaTeX command set, except they're native Unicode and native OpenType support. That's kind of where the full stop should be satisfactory. If you need to typeset anything, having the LaTeX commands _and_ normal text typesetting for arbitrary languages is literally why base LaTeX with pdftex is now effectively irrelevant.

If you need amsmaths or APA citation, you still get those. Except now you get them without insane commands just to type Paul Erdös' name, or citing Лев Семёнович Вы́готский.


I guess I live in a small world because I have no idea how to type an umlaut on a US Qwerty keyboard but I can easily type Paul Er\"{o}s.


The irony is that it's Erd\H{o}s


Have you tried the setxkbmap -layout us -variant altgr-intl keyboard variant? See https://www.google.com/amp/s/zuttobenkyou.wordpress.com/2011...


Option-u o


It's Erdős, not Erdös btw.


I was kind of hoping someone would point that out.


You're welcome.


Greek characters require a few manipulations (loading babel and using \textgreek{}), but for accents you literally just need to add two lines to your preamble:

     \usepackage[utf8]{inputenc}
     \usepackage[T1]{fontenc}


Or you use XeLaTeX and you don't do those things. You just write Greek and say you want to use whatever normal font you like best for typesetting English and Greek at the same time. Because the "inputenc" package shouldn't be necessary in 2017. For more than obvious reasons, _everything_ is now utf8 encoded, including ascii files. Unless you live in a CJK country. Then you might have a reason to still use BIG5 or JIS... although that reason is slowly eroding in favour of UTF8 too.


For the use case where your journal/publisher has a desired LaTeX template, it's probably more pain than it's worth.

For works that have to handle multiple scripts, and for works wherein you are in control of your own typography, it's more logical and practical to work with XeLaTeX/LuaLaTeX. If you wish to use OpenType or TrueType fonts there's little debate.

If you want to go the whole nine yards regarding Unicode, there's recently been some development regarding Unicode math, with the first impetus being Microsoft and its Cambria Math to support mathematical typesetting in Word. Unicode math refers to fonts implementing mathematical symbols as Unicode glyphs, as well as some font-side logic regarding how the font renders math, afaik.


Not really? XeLaTeX is "the LaTeX API (because it's an API built to be run by a TeX engine. LaTeX is built on TeX the same way jQuery is built on JavaScript) run using XeTeX" (the natively-unicode-aware TeX engine).

So if your publisher has a LaTeX template, that's pretty much guaranteed to work just fine when you \usepackage it in XeLaTeX context. Needless to say, except it really does need to be said, that also means full Unicode Maths support (through \setmathfont{A normal font name} without needing TeX metrics nonsense because it's 2017) for any OpenType font with maths support (Cambria Math, XITS Math, etc. etc.)


I was thinking that if you draft a document in XeLaTeX/LuaLaTeX, including a template, then if you don't bother to really learn how font handling with XeTeX/LuaTeX works, you might end up with some fontspec or polyglossia line in your code, etc., and there might be problems with a template that does things oldstyle.

Another point is that some packages haven't been updated for Unicode, algorithms2e being one popular package that's still Latin-1, IIRC.

Then if your code will be compiled from source by someone using pdfLaTeX, your Unicode characters will cause problems.

Hence why I say that it's probably more pain than it's worth, since there are still things you need to understand to avoid incompatibility. I think a more proper analogy would be C and C++, since while XeTeX/LuaTeX is mostly LaTeX compatible, 1) you risk running into sinister incompatibilities and 2) typical XeTeX/LuaTeX code is different from, and incompatible with typical LaTeX code.


I've spent time on LuaTeX, and I'd really like to understand changing the font.

For example I can list them with: mtxrun --script font --list --all

But when I try to use "gonormal" ( \definefontfamily [myfam] [tf] [gornormal] ) I get: "The requested font 'gonormal' has no files for the 'tf' alternative, Latin Modern is used instead."


\usepackage{fontspec} and you're done. \setmainfont{Palatino Linotype} to just use that, \newfontfamily\secondary{Times New Roman} now you can just stick in {\fontspec{\secondary} blah blah blah} for bits you need styled in a different font for a few words/sentences/paragraphs/however much you need.

And if you need the automatic TeX style replacements (like turning `` into opening quotes - personally, I hate that, I'm writing text, not programming - then you can pass in TeX mapping instructions in [...] blocks, covered by the fontspec manual: \setmainfont[Ligatures=TeX]{Font By Name} and \newfontfamily\whateveryoucallit{Font by Name}[Ligatures=TeX])


Writing prose is easy no matter what tool you're using. Now try to typeset a matrix that has annotations for its rows and columns. Say something like

       m n
     [ A B ] m
 X = [ C D ] n
     [ E F ] n
Achieving this in LaTeX deserves a dissertation in and of itself.


    \documentclass{article}
    \usepackage{blkarray}
    \usepackage{amsmath}
    \begin{document}

    \[ X = \begin{blockarray}{rrr}
    m & n \\
    \begin{block}{[rr]r}
    A & B & m \\
    C & D & n \\
    E & F & n \\
    \end{block}
    \end{blockarray} \]
    \end{document}


Sweet! For some reason I remember having bad interactions between blkarray and other packages, but I can't reproduce anymore...


Or you can use TeXmacs [1], enter such arrays in WYSIWYG and export to LaTeX.

[1] http://texmacs.org/tmweb/home/screenshots.en.html


The result doesn't prove how arduous the process to find that out can be. Latex stackexchange is a rich recourse though, and your help is certainly welcome. I'd still call it LaTe-X :P


Latex still is the least bad option for technical writing. I never get used to Word's figure captioning, numbering and referencing, and although the equation editor is vastly improved, multiline alignment is still tricky. And version control of documents of course! I hate those report_v23_JohnReview.docx systems.

Also, +1 for TexStudio!


There are also pandoc[1]-based markdown extensions which can create both latex and html. Today I was looking at an R Markdown[2] derivative, bookdown[3]. And was amused by Tufte style[4].

[1] http://pandoc.org/ [2] http://rmarkdown.rstudio.com/ [3] https://bookdown.org/yihui/bookdown/ [4] http://rstudio.github.io/tufte/


We used ShareLatex.com for engineering projects in college, and it eliminated the complexity of having to install LaTeX on everybody's computers. It also allowed us to export the source for safekeeping [1]. I would use it again in the future.

[1] e.g. on Github: https://github.com/philipithomas/SchedulingPaper


It's free software as well! https://github.com/sharelatex/sharelatex (AGPL)


Also Overleaf (used to be writelatex.com) https://www.overleaf.com/


Although docker could be pretty handy for this these days.


Looking through here, haven't seen anyone using Pandoc, so I'll through that in the mix. Offers the ability to write simple LaTeX intertwined with Markdown. I've been using it for everything from letters to homework assignments, seems to get the job done for most scenarios. Probably wouldn't use it for an extensive paper though. But it's nice to be able to start typing in Markdown, call `pandoc -o output.pdf source.md` and just have something nice to send out without a ton of setup.


I've written both my bachelor's and master's thesis using Pandoc and Markdown with occasional LaTeX markup.


1. Install TeX Live and TeXstudio

2. Start writing your master main.tex file

3. Search a bunch of StackExchange forums, edit main.tex appropriately

4. Now you have to edit /usr/share/texmf/tex4ht so your epub converter renders images properly

5. Finish your book. You will never touch that main.tex again, you will use it for everything from now on and take it to the grave


While making sure to tell TeXstudio to use XeLaTeX or LuaTeX, and never the LaTeX/pdftex (unless you live in such a small world you never need a single non-ascii English character of course. Then stick with pure LaTeX)


\usepackage[utf8]{inputenc}

\usepackage[LANG_OF_CHOICE]{babel}

solves that problem.

there's plenty of font packages available for pdflatex.

I use newtxmath and newtxtext and libertine math and text all the time.


No it doesn't: you just told me to "choose a language". It's 2017, why would I choose a language when I can just use all the languages with XeLaTeX, using:

   \usepackage{fontspec}
   \setmainfont{Noto Sans}
and that solves that problem. I can write whatever I want, and stick in lang-specific context switches using \usepackage{ucharclasses} (for making sure macros are inserted for transitions to/from specific unicode blocks) only once I absolutely need them, and no earlier.


You haven't really explained why it doesn't.

Choosing a language allows you to automatically translate a bunch of strings used by various packages.

For examples Chapter, Section, TOC and everything that is autogenerated will be translated to a language. It has nothing to do with utf8.

You can remove babel and Chinese, German, Swedish can work in the same file regardless.

\usepackage{noto}

What's hard about that?


Emacs and Auctex and you're done! (Provided you already use Emacs...)


If you're using Emacs already, just use Org-mode to write your documents and C-c Ce l p, i.e. export to pdf through latex. I use a combination of Org-mode and xelatex, and it works like a charm. Just set up `org-latex-classes' to your templates if necessary, then:

  ;; See: https://lists.gnu.org/archive/html/emacs-orgmode/2014-05/msg00198.html
  (let
   ((xelatex "xelatex -shell-escape -interaction nonstopmode -output-directory %o %f")
    (biber "biber -u -U %b"))
   (setf org-latex-pdf-process
         (list xelatex xelatex biber xelatex)))
and go.


org-mode is wonderful and exporting is a great feature. But it's more about using LaTeX as a convenient way to get a typeset PDF. But I've never successfully completed a "real" paper or book using just org-mode. I always end up adding a ton of manual hacks and at that point I might as well skip org-mode entirely.


This. And it even comes with reftex and bibtex.


It's great but the author already says he uses it. It doesn't run LaTeX multiple times, though, as far as I know.


I wrote sshlatex to speed up compilation. It does what you think it does, it runs LaTeX on a remote server and streams the resulting PDF document. The LaTeX header gets precompiled, shaving a couple of hundreds of milliseconds. It's therefore also useful when used only locally.

https://github.com/iblech/sshlatex


Can vouch for ShareLatex - used it to write my Masters dissertation (Maths) and use it to maintain my CV. Lots of handy templates for everything and no need to faff around with infrastructure.


Yes, it has a lot of nice features, but the monthly subscription price is simply way to high for me.


As the unoffical Racket Evangelist has anyone looked at Scribble?

> Scribble is a collection of tools for creating prose documents—papers, books, library documentation, etc.—in HTML or PDF (via Latex) form. More generally, Scribble helps you write programs that are rich in textual content, whether the content is prose to be typeset or any other form of text to be generated programmatically.

https://docs.racket-lang.org/scribble/


I use LyX. It's interactive and visual, it generates clean and correct LaTeX, and it builds it for you, so you don't need to muck around with error-message parsers and makefiles.


Me too. It's also extremely flexible, at the cost of not in fact always generating correct LaTeX and sometimes needing a whole lot of debugging.

I use LyX because, although I'm a programmer and perfectly capable of littering my text with braces, somehow that completely ruins my writing flow. I need the text I'm writing to look clean and a bit formatted (big text for headings, italics and suchlike) -- and not like code -- to get anything meaningful down on paper.


I've always been confused when people talk about tooling for their programming languages. It made me fell like, maybe, I was doing it wrong by using a console-based text editor along with whatever compiler / interpreter is appropriate. This article finally made it clear to me that "tooling" means "a Rube Goldberg device I cooked up instead of learning how my programming language works." LaTeX is a lot easier if you understand what it's doing for you.


On iOS and OSX, TexPad.com apps work very well. Not affiliated but prefer TexPad over all other editors. Even works with git clients on iOS.


I wonder what the author would replace LaTex with . . . ?


Something better :)

Honestly, nothing is 100% convincing, but if I could pick anything, I'd use HMTL with some templating magic (for generating references).

It still leaves the issue of positioning floats and page breaks, which is really non-trivial, even if you already had a "spatial model" of what the generated HTML would look like (I know of no such library, but do tell if you know of it).

TBH, floating figures is a non-issue for the web, where you can just position them in the flow. It's only in print that this is an issue. I'd be fine to put figures on separate pages, but that might be a waste of paper.


Step 1: touch report.tex Step 2: latexmk -pvc -pdf report.tex Step 3: ??? Step 4: PROFIT


What the OP describes is really long, drawn out, complicated mud wrestling.

I've been a good TeX user from the beginning of TeX and love TeX.

For the problem the OP addresses with LaTeX, there is a much easier solution: And the candidates are ..., and may I have the envelope, please? [drum roll]. And the winner is ["rip"]: Just use just TeX, that is, D. Knuth's TeX with his standard macro collection Plain. If get into trouble, then just get and read his book, The TeXBook -- as software documentation, it is exemplary.

I'm guessing that a TeX file sent to people who accept LaTeX will work fine. That was the case the time I published in the Elsevier journal Information Sciences.

Want some cross reference macros? Okay, I put my TeX macro source code for cross references at

https://news.ycombinator.com/item?id=13630570

in two parts in two posts where the above URL is for the first part and the second part is close in the same HN thread.

The OP goes on and on about what text editor to use for typing in documents in TeX. No problemo! I just use my favorite general purpose text editor KEdit with a few macros specific to TeX.

With the TeX distribution I have is the spell checker ASpell. I use it for nearly all my spell checking, in blog posts, e-mail, sure, TeX, source code documentation, own notes on random subjects, etc. ASpell was written by a bright, hard working person -- it's darned nice software, one of my favorite tools. I use ASpell just for English, but IIRC it also can work with French, German, etc.

TeX is fixed and unchanging, rock solidly standard, essentially totally bug free, beautifully designed and documented -- what's not to like?

LaTeX? Just to start, need at least two books, each about twice the size of Knuth's one book, and IMHO nowhere nearly as well written (likely the case since next to nothing in software or computer science is written as well as Knuth's book). For more, of course there is the TeX source code documentation in Knuth's literate programming which I've long regarded as just exemplary software development -- that is, IMHO the most important part of software is the documentation, clear enough to make the actual programming language statements obvious because otherwise when the code is written "only the programmer and God understand it and six months later, only God".

TeX was good enough for Knuth's book and, then, his series The Art of Computer Programming and, thus, should be up to the needs of a journal.

Or, in short, just use TeX, with your favorite editor (hopefully a good one that lets you write some macros), write some TeX macros, use ASpell, and otherwise avoid the mud wrestling and relax!


Interestingly, I thought of doing this, and still might.

The biggest caveat is that you still have to rely on the buggy conference templates (or spend a lot of time recreating them).


TeX is essentially a programming language for typesetting. I sigh when I think of learning a new language for such a narrow purpose. You make this sound easy but I have Knuth's book and have seen enough of it to know this isn't easy. If it were, no one would have been motivated to write or use LaTeX in the first place.


> TeX is essentially a programming language for typesetting. I sigh when I think of learning a new language for such a narrow purpose.

Yup, and "sigh" is a mild version.

I don't remember saying that TeX was "easy".

Actually, for just text, TeX can be quite easy, as easy as, say, HTML, old WordStar, Word, the old Runoff programs, etc. That is, just need to know a few tags.

The difficult parts are doing more, lots more, especially typesetting some mathematics with some tricky notation. It's fair to say that, just due to mathematics and its notation, fundamentally there is no "royal road" to typesetting all of mathematics -- much of it, yes, all of it, no.

I confess I spent a lot of time in Knuth's book. At one point I wrote a verbatim macro and like it better than what Knuth has -- verbatim is tricky because need to cancel temporarily a lot of what is in TeX. I wrote the macro so that I could document with the source code TeX macros in TeX documents. At the time, that seemed important -- I no longer believe it is.

Also I wanted to use TeX as the formatting language for my old daisy wheel printer, say, instead of old PC WordStar or some such. At the time, that seemed important. Nope, it wasn't.

But for business cards? Yup, TeX has been nice. Can get some sheets to run through a black and white laser printer. The TeX is cute, say, have the TeX for one business card and, then, use more TeX tricks to position the results for one card on all the cards on one sheet. Then bend the sheets and get a stack of cards -- they look good enough (somehow the edges are clean enough).

But I've got the macro; writing it is a good TeX exercise.

Maybe have to look at TeX in about the right way. Or, from a movie, "I'll love it when it works." with the response "It will work when you love it." Or, love it for what it is good for; don't hate it for what it's not good for. TeX is not good for everything.

What is TeX good for? Sure, Knuth's books in his series The Art of Computer Programming (TACP) and, okay, also papers in, say, the American Mathematical Society (AMS) journals.

Or, TeX is to do on a computer what typesetters used to do by hand for math text, many physics and engineering texts, TACP, and the AMS. So, right, TeX is not the ultimate way to put any and all marks in color, etc. on paper or a screen now and in the future. For the future, really, TeX was to computerize the old work of math typesetting, not create a new future in formatting or putting wildly conceived marketing materials on billboards, handbills, TV, or computer screens. E.g., I don't see an easy way in TeX to wrap multicolored, stretched text around a sphere and have it rotating with sparks flying off -- maybe Knuth could use TeX for that! I see no way to do ray tracing graphics in TeX. TeX doesn't replace everything from Adobe or HTML5 or be the sole tool of all graphic artists, movie makers, etc.

But if you want to be able to type math, and I do, then TeX is just fantastic -- beautiful results and, for such good results, by far the easiest approach.

If look at Knuth's book and insist on just an introductory tutorial for an hour or so and just f'get about the rest, then you should do okay at first. As you want more, say, ordered lists, unordered lists, simple lists (I have some simple macros for each of those three, with the logic for some nesting), good control over page breaks, exact control on space after periods, positioning of figures, using TeX to put math annotation on a figure (basically have TeX print on top of the figure -- actually easy enough once see how it works), some fancy foils format, essentially automatic tables of contents, cross references, a nice way to do references (I have a good enough way but don't use BibTeX), getting good with font magnification, handling hyphenation in detail yourself, tricky tables (they are not so easy in HTML, either -- about the only easy way to do tables is with just flat ASCII and assuming a monospaced font!), then look some things up in The TexBook.

I believe you will find that the simple stuff can still be simple. And for the math, say, at the level of freshman calculus, that's actually quite natural and easy also.

IMHO, LaTeX is more difficult. Maybe LaTeX makes it easier to have some book format with title page, frontispiece, preface, table of contents, fronts matter, body, parts, chapters, sections, subsections, back matter, tricky running headers and footers, references, colophon, etc., but, gee, Knuth wrote his book in TeX and not everyone is trying to write the Encyclopedia Britannica.

If something seems really challenging in TeX, then maybe don't really need to do that. Or get some help from the KISS princple -- Keep it Simple Sam.

E.g., for KISS, consider HN: How can post pictures? Can't do that. How can include TeX math? Nope, not there. How about bold face? Can't do that either. How about ordered lists nicely indented? Not there. Still HN is darned useful.


Needing all that "tooling" for a word processor is embarrassing.


That's literally the difference: this isn't word processing, it's typesetting. If you want word processing, use a word processor, and trust it to make the right choices for you. However, if you've spent any amount of time actually trying to get those images placed correctly, or those page dimensions perfect, word processors fall short and your only other option is a TeX engine, or typesetting applications like InDesign. Of those two, one category is free, and the other costs $50 a month these days.

Certainly this is the case when you need to typeset maths, but even when you want proper typesetting control over something as "simple" as mixing English and vertically typeset Japanese, Word and friends are insanely ill-equipped to do what you need them to do, whereas a modern TeX system like LuaTeX or XeLaTeX will actually let you define what you need and then get out of your way from that moment on.


> if you've spent any amount of time actually trying to get those images placed correctly

I had to learn LaTeX as part of my education, and as much as I like it this is one of it's weaknesses, not it's strengths. I saw my fellow students struggle to get all the images on the pages they wanted, and if they asked for help the answer was "Let LaTeX decide where to put it".

Don't get me wrong, I still love LaTeX. It let's me:

  * Keep a whole document in a consistent style I can change at any point in the process.
  * Produce pretty mathematical formulas and proper justified text.
  * focus on writing instead of fiddling with where images go (I let LaTeX decide, it's usually pretty smart about this)
  * Write code that writes part of my document. I used to write code to do the boring parts of certain proofs, and it would produce the LaTeX for me.


> and the other costs $50 a month these days

I appreciate your point, but it's actually $19/mo for InDesign.


The point stands, with that revision, which can't be worked in due to hackernews not letting you edit your comment indefinitely.


With LaTeX one needs a bunch of tooling to get things done.

With Word, LibreOffice or other alternatives, it's impossible to get things done no matter how much tooling one adds, because they simply cannot do what LaTeX does.


You don't "need" it. Install your favourite latex distribution and use an editor and latexmk. Works fine. Still better than every office suite or web app for academic articles, at least in STEM fields.


I love the feature of Latex where you remove one brace from your code and then it breaks entirely with the very helpful memory overflow error. Great compiler.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: