76

I would really love to have a software or tool which provided real time compilation of my LaTeX document (to be able to see the final pdf or dvi document as I type the latex code), especially for when I am drawing pictures using tikZ. So far, I know of two things, but none of them work for me. They are:

  • KtikZ: This is only for tikZ, which would be perfect for me, but unfortunately as far as I know it only works with Ubuntu and Debian, and I use Mac OS X (so I have never actually tried it, though I did dig a lot to see whether I would be able to install on my mac and from what I see it is really what I want - I am even considering installing Ubuntu just to use it!).

  • WhizzyTeX: This is a minor mode for Emacs. It was extremely hard to get it to work on the mac (see my quest here), and it is not all that fast. The speed is not all that big of a deal for me, but the fact that it does not work with tikZ pictures is (the nodes all collapse in one point so that the words are all one on the top of the other).

So my question is: is there a software ideally like KtikZ or another type of editor which provides real-time compilation and that I can use on my mac? I guess if you know of a Windows/Linux option I would also like to know, and the same for a way to set up a script to get the document compiled every 5 seconds or so (I am sure I have seen this written somewhere, but I don't know whether I can do it with a mac or whether it is editor/pdf viewer dependent), but what I really want is a software/tool which would work with a mac.

To be clear, I am not after something like LyX, that is, I am not after a WYSIWYG-type thing, but rather something where I can type real LaTeX and see my code, but have at the same time another window showing me the pdf (or dvi) file compiled.

19
  • 8
    You can use Qt, the windowing toolkit for Ktikz, natively with OSX. Compiling it is brutal (took me 25 hours, on an old ibook), but the integration is nice. None of the other dependencies of Ktikz look problematic, and I think they're all in Macports. You should then be able to compile the sources without trouble, following the instructions at lwn.net/Articles/274725 Jul 30, 2010 at 9:46
  • 1
    @Charles: this information is potentially life-changing for me! I spent hours, days, looking for anything like that, but couldn't find. I got a friend to try and compile it in Fedora but he couldn't make it work even there!! The problem is, I have never compiled anything, and I don't even know where to start. Those instructions (if they apply to OSX as you say, because that isn't clear to me) are too advanced for me. I don't know what dependencies are either. But again, I thank you for the tip. I will hassle someone to help me try the process :)
    – Vivi
    Jul 30, 2010 at 10:30
  • 1
    I'd agree with Charles that you should look into compiling Qt and the KDE libraries on your Mac. If you aren't able to coerce a friend into helping you ;-) Super User might be a good place to ask for more detail on how exactly to do it. (You'll be very familiar with running commands from the terminal by the end)
    – David Z
    Jul 30, 2010 at 19:10
  • 4
    The homebrew package manager for OS X can compile both Qt and the KDE core libraries. Check it out at mxcl.github.com/homebrew. Then brew install qt and brew install kdelibs.
    – Sharpie
    Jul 31, 2010 at 3:08
  • 1
    Well... it didn't work "out of the box" for me. With the source code, a few beers, and a couple hours on the Ballmer peak it could probably be straightened out.
    – Sharpie
    Aug 3, 2010 at 21:43

24 Answers 24

33

On a Mac, you can of course just open up a terminal, cd to the directory where you keep the TeX file, and issue

while true; do sleep 5; latex -halt-on-error filename.tex; done

and have the DVI file open in a viewer that watches for (and reloads on) changes. The one-liner runs latex continuously with 5 second break between runs (the -halt-on-error options prevents the incantation from getting stuck if you saved a file with errors). You can also swap in pdflatex instead.

This solves half of your problem. The other half has to be dealt with by your editor of choice. You need to set it up to automatically save the file every x seconds, and how to do that depends on the editor at hand.


Now, that one-liner I gave above is quite ugly and resource wasting, since it makes no sense to re-compile if no changes are made (Edit: See this comment below for a much better way to avoid this problem). So you can do something like

while true; do sleep 2; if [ filename.tex -nt filename.log ]; then latex -halt-on-error filename.tex; fi; done

which watches for changes to the TeX file (signaled by the fact that filename.tex is more recently modified than filename.log) and compile when necessary (with a possible two seconds delay).


Short of a WYSIWYG, I am not quite sure how you can achieve full real-time solution. Compiling the code takes usually a short amount of time (1 or 2 seconds, or more if the file is large). So if you are looking for a solution that calls the LaTeX compiler, it probably shouldn't try to do it more often than once every 5 or 10 seconds. So you won't be able to immediately see what you typed in the DVI window. Also, if the editor autosaves the file in a spot where you are halfway typing a command, then the source won't compile.

With LaTeX I feel that the better idea is "compile-on-saves", where the human initiates the saving of the file (as compared to "automatically saving and compiling in the background). For that, modern editors can generally support hot-keys where saving and compiling is mapped to one keystroke. In vim I map F2 to compile and F4 to call XDVI.

7
  • By the way, the shell scripts listed are given for bash, which newer OSX machines defaults to. The older ones default to tcsh, so I am not completely sure if the second one will work. Jul 30, 2010 at 14:26
  • I've done something pretty much the same with a python script.
    – vanden
    Jul 30, 2010 at 14:43
  • 28
    The latexmk program, which comes with most TeX distributions, when run with the -pvc will do everything the above does, and better. (Watch the file, recompile whenever it changes, run enough times to resolve all dependencies.) But it still doesn’t offer the true live-updating experience that you get with Gummi and WhizzyTeX.
    – frabjous
    Aug 5, 2010 at 2:00
  • 1
    You could also use the watch command instead of the sleep loop Aug 24, 2012 at 14:00
  • 2
    You could use inotifywait (see this unix.se answer) in monitor mode to trigger the compilation precisely after write access Oct 22, 2012 at 13:47
39

Latexmk has an option that will compile your document every time you save it. It requires Perl. There is also some very useful information in this Stackoverflow question about how to work with latexmk when you document has errors (which can happen a lot with TikZ).

2
  • Thanks for the answer, but this is really not what I am looking for. I want something that will do it on the fly, without having to prompt it to do it. The way it is for me now, the effort to save and to compile my document is the same (C-x C-s or C-c C-c) and once I compile it my viewer updates the file.
    – Vivi
    Jul 30, 2010 at 20:50
  • 8
    You could set emacs to save every half second and use latexmk -pvc Jul 30, 2010 at 21:07
16

Claus Gerhardt's Flashmode offers live preview for TeXShop on MacOS. From that page:

Flashmode enables simultaneous typesetting if TeXShop is used as editor for TEX or LATEX or any other common TEX variant. When Flashmode is started, it looks for the front most document in TeXShop, gets its path and after that it is hooked forever to this document as long as it stays open, i.e., a few split seconds after Flashmode has started the front most document in the TeXShop could be anything without doing any harm.

Then Flashmode checks in regular intervals (default is 0.2 sec), if its tex document has been modified, and if so, it initiates a save, a pdflatex run, and asks TeXShop to refresh the corresponding pdf file. Flashmode can be invoked even if a document isn’t typeset yet, but beware that its first action will be a typesetting command.

An important feature is that tex syntax errors don’t cause any error messages or disruptions of any kind, i.e., the pdf gets never corrupted, at least the pdf viewer is never aware of it, and the last refreshment is always visible; the pdf viewer will never complain.

Thus, the user never gets any error messages; the presence of errors can only be deduced from the pdf window which then doesn’t change any more; of course the errors will be reported in the log file and can be looked up.

0
16

Linux has a relatively new editor called Gummi that gives real-time output. Unfortunately it has crashed a few times for me (which is a few times too many). I plan to watch this editor closely as it becomes more stable.

I currently use Ktikz to edit my LaTeX documents in real-time. By default only tikz pictures are compiled, but by simply writing an empty template with the text

<>

ktikz will compile an entire LaTeX document.

1
  • Yeah, gummi provides the best live updating preview I’ve tried; better than WhizzyTeX anyway. Earlier versions crashed on me too, but so far the newest one hasn’t, but I’m still a bit nervous about it too.
    – frabjous
    Aug 5, 2010 at 1:57
13

Bakoma-TeX (http://www.bakoma-tex.com/) has a "true Wysiwyg" interface. Stable for Windows and "test" versions for Mac and Linux. You can find a favorable review at http://www.economics.utoronto.ca/osborne/latex/BAKOMA.HTM.

I sometimes use it, although I usually do not think it is worth the bother. TeXworks and frequent recompiling work well enough for me.

3
  • I didn't know about that. The fact that is being reviewed by an economist is a plus for me :P
    – Vivi
    Sep 15, 2011 at 4:02
  • Bakoma is the best choice, if you want to pay for it!
    – user565739
    Oct 5, 2012 at 14:00
  • This is the only correct answer on this page. BaKoMa is much more advanced than the other solutions: it caches the output of the renderer after each page is complete, so when making edits on page $n$ of your document, it recalls the state of the engine after compiling page $n-1$, and only has to recompile a single page. For me this is transformative for writing TikZ code. I genuinely think it is one of my most powerful "secret weapons" as a researcher. Unfortunately the developer Basil Malyshev recently passed away and so the project is no longer being updated. Jan 13, 2022 at 11:45
8

WhizzyTeX was mentioned in the question with the remark (emphasis added):

The speed is not all that big of a deal for me, but the fact that it does not work with tikZ pictures is (the nodes all collapse in one point so that the words are all one on the top of the other).

I'd like to counter that by pointing to a question: How can I execute a macro for every node in TikZ? where the aim was to figure out how to make TikZ nodes "draggable" in the WhizzyTeX-ADvi combination. I've now used that combination successfully to "fill in" a PDF form so can confirm that it works. Thus WhizzyTeX does work with TikZ pictures. It may need some development to get it to work in full - I've only used it in a rudimentary fashion - but certainly for nodes then it worked just fine.

Edit I just looked at the WhizzyTeX developer's homepage where it is clearly stated:

WhizzyTeX --- Version 1.3.2 of Aug 2, 2011 (works with pgf and beamer)

8

The LaTeX editor Kile now offers a live preview feature in its development version. It's still experimental.

Requirements:

  • PDFLaTeX with SyncTeX support (offered by TeX Live 2010 and 2011, for example)
  • Development version of the Okular viewer
  • Development version of Kile

More details can be found here: Live Preview with Kile.

0
6

there exists only one real WYSIWIG editor http://mirror.ctan.org/systems/win32/microimp/microimp.pdf, which was the first and last try to create one for LaTeX. In general: it is not possible to have a WYSIWIG editor! A user can overwrite anything of the existing code or define anything new. This makes it nearly impossible to write such an editor.

What you can have is an editor which runs in the background ???latex when the source code changes. But this implies two windows, input and output, like Gummi does: https://github.com/alexandervdm/gummi

2
  • This was an interesting project. I remember EquationMagic (a product of MicroImpress for Windows) was my introduction to LaTeX back then. Does anybody have a screenshot or a video of how VTeX GUI used to look like.
    – alfC
    Jun 29, 2014 at 20:47
  • microimp is a dead project.
    – user2478
    Jun 29, 2014 at 20:56
6

You may opt to use tikzedt.

Features:

  1. Syntax highlighting and code completion, based on AvalonEdit.
  2. Real time rendering, using pdflatex and mupdf.
  3. It contains a Tikz parser, built using the Antlr parser generator.
  4. Parsed coordinates are displayed as an overlay on the rendered image. The overlay can be edited with the mouse in a WYSIWYG manner. The source code is updated accordingly.
  5. It comes with a snippet library to store frequently used commands and styles, containing many pre-defined examples.

According to the New features in version 0.2.2 of tikzedt:

One can use an external pdf renderer (mupdf) for better rendering quality. To do this, copy mudraw.exe into Tikzedt's program folder and change the rendering method in the settings. Customization of editor font. Version for Linux, and MacOS (to be tested) Bug-fixes

enter image description here

[Edit: For Mac OS X, see this page.]

Another option may be to use TikZ-Editor

enter image description here

The features include:

  1. simplistic and dedicated GUI : Tikz Editor is only about TikZ.
  2. Syntax highlighting for TikZ/Latex sources.
  3. Real-time preview of figures.
  4. Customizable code snippets.
  5. Feedback of LaTeX typesetting errors using source annotations and margin markers.
  6. Separated edition of TikZ source and LaTeX preamble.
5
  • Picture for tikz-editor is from their github site.
    – user11232
    Jun 4, 2013 at 12:53
  • I can't get either option to work. Both say they can't find the command pdflatex :(
    – Vivi
    Jun 4, 2013 at 21:57
  • @Vivi :( Sorry. I am not on Mac. Somewhere in the settings you may have to indicate the path to pdflatex. But things should be taken automatically. Let me dig to some extent.
    – user11232
    Jun 4, 2013 at 21:59
  • @vivi For tikzedt, can you specify the path to pdflatex in Settings > Settings > General (tab)? What happens then?
    – user11232
    Jun 4, 2013 at 22:03
  • I am completely useless when it comes to this more complicated stuff (specifying path, commands to compile, etc). I will ask a question later to see if I get this to work. Also, although tkzedt seems like a better piece of software, it is not made for the mac, so I will probably stick with the other option (tikz-editor) for now. Thanks for the help, I think you have done more than I could ask for!
    – Vivi
    Jun 4, 2013 at 22:11
5

Overleaf (Web)

enter image description here

Overleaf is the new collaborative writing and publishing system developed by the team behind the popular writeLaTeX editor. Overleaf is designed to make the whole process of writing, editing and producing scientific papers much quicker for both authors and publishers.

BaKoMa TeX

enter image description here

BaKoMa TeX is an innovative TeX/LaTeX implementation with BaKoMa TeX Word - a Visual (True WYSIWYG) LaTeX Editor.

Kile

enter image description here

Kile is a user-friendly TeX/LaTeX editor for the KDE desktop environment. KDE is available for many architectures and operating systems such as PC, Mac, and BSD, including Linux and Microsoft Windows.

Currently, the following three experimental features are under development:

  • live preview
  • user-configurable menu
  • extended scripting interface
4

TexShop (also available through MacPorts) does a save on compile. It has a preview window so you can see your compiled document as you go.

9
  • TeXShop comes with the default MacTeX distribution, so you shouldn't need to install it via MacPorts, though. Jul 30, 2010 at 18:03
  • 1
    As I said in a comment to another answer, this is really not what I am after. I want something that compiles without having to do anything, not even save the file. I want an on-the-fly compiler. Thanks for the answer, I am sure it will be useful for someone :)
    – Vivi
    Jul 30, 2010 at 20:52
  • @ShreevatsaR Package management is an amazing thing.
    – Jeremy L
    Aug 1, 2010 at 15:37
  • @Nerdling: Yes of course (though package management on MacPorts is awful and bug-ridden in my experience, relative to the standards of, say, Debian), but why would you want to install something that's already present on your system? :-) Aug 4, 2010 at 7:04
  • @ShreevatsaR Neither MacPorts nor TeXShop came on my system. What do you mean?
    – Jeremy L
    Aug 4, 2010 at 12:07
4

Latexian offers a live preview on OS X.

4

MacKichan's SWP, SW, and SN are WYSIWYM (what you see is what you mean) editors, which do not give you the compiled pdf or dvi file without compiling, but compared to a source code the view is quite advanced. There are trial downloads available: http://www.mackichan.com/licensing.net/dnloadreq.aspx, but frankly I would wait purchasing it until the next version (which shall include eTeX and the ability to update everything to the latest versions at CTAN instead of being frozen at - , well, I guess it is 2002?).

3
  • The current version of SWP does not work on the Mac. Also, I was pretty clear that I wanted something where I could type LaTeX and see the compiled version at the same type (rather than type in something that looks like Word and you don't need to know LaTeX). That said, SWP is not so bad.
    – Vivi
    Sep 13, 2011 at 4:07
  • SW has a wonderful interface, but one should really not use it. It has a number of features which make it basically impossible to use many of the useful features of LaTeX. For instance: it expands all \newcommand and saves the file with the expanded version; it rewrites the part of the file before the \begin{document} moving all comments to before the \documentstyle; any text within an environment that it does not know of is presented in a dreadful little gray box and basically non editable. It generally encourages incompetence in the use of LaTeX. I have co-authors who use it, and hate it. Sep 14, 2011 at 1:36
  • That is why I said "frankly I would wait purchasing it until the next version" - hoping the next version will have corrected everything. Well, there is a demo, thus when the next version is released, we can check whether it has been fixed. About "encourages incompetence in the use of LaTeX" you are totally right.
    – Stephen
    Sep 14, 2011 at 18:04
3

As a completely different option you might want to consider, it is also possible to use an editing program that exports TiKZ files. This may be perhaps the most responsive option, unless you have a super-zippy machine to run TeX. As mentioned by Andrew Stacey in an answer to an earlier question, the Inkscape extension inscape2tikz generates TiKZ output. If you don't care too much about the readability of the TiKZ code this would be worth a look.

2
  • 3
    Oh, no, I love writing tikz code! I don't use tikz so that I have a picture in code, I use tikz because I can write my picture using code!! For me, this is a bit like using Scientific Workplace or Lyx to write LaTeX. Easier, but not as flexible or interesting!
    – Vivi
    Aug 3, 2010 at 21:41
  • I understand your stance -- this is my attitude too! Aug 4, 2010 at 7:08
3

I can recommend a program similar to Ktikz, CirKuit, which I've been using successfully for quite a while. It enables you to create not only TikZ pictures, but also circuit diagrams using the Circuit macros.

2
  • But this is for Linux, isn't it?
    – Vivi
    Aug 22, 2010 at 1:30
  • No, it's for KDE, just like KTikZ is. It should be possible to run it on Mac OS or Windows - any place you can use KTikZ, you should be able to use CirKuit as well.
    – David Z
    Aug 22, 2010 at 3:29
3

Texpad developers here. In case it helps: On OS X, Texpad features Auto-Typeset that detects a pause in typing and sets a typeset operation off. The feature is configurable and you can try it out in the demo at texpadapp.com/osx.

2
3

I have made a live preview plugin for WinEdt editor. It will show the preview of current paragraph in the upper right corner of WinEdt. Furthermore it will update the preview automatically if current paragraph has been changed.

enter image description here

3

I made a plugin for Neovim called KNAP (Kevin's Neovim Auto-Previewer) that provides a live compiling/live-updating preview of LaTeX files in the PDF viewer of your choice.

KNAP live preview

It works also with Markdown, HTML or other files you configure, though I made it with LaTeX in mind chiefly. It also supports SyncTeX (so long as the viewer does), subdocuments, etc.

The readme (main page on bitbucket) has configuration instructions for quite a few different PDF viewers, and the information there might be of some use even for people who don't want to use neovim/my plugin, and want to configure some other editor or tool.

Only tested on Linux, at least by me!

2

The best and by far most complete attempt towards live preview I have seen so far has been the iTeXMac project. It does not only provide instant preview – optionally even the editor cursor position is visualized in the PDF preview as you type, which comes pretty handy when editing a complex formula or table!

Unfortunately, the project seems to be dead :-( The current beta claims "Tiger-Compatibility" and there hasn't been any progress for years. It probably still runs on current OS X versions (my last test was with Leopard or Snow Leopard), but is too unstable to be usable for serious work. Nevertheless, I still consider it as a good lesson on what to dream for :-)

1

TeXlipse automatically compiles the document on save and I usually have the PDF open (in Preview on Mac OS X or in evince on Ubuntu 10.04, which both automatically show the updated PDF if it is changed).

1

Regarding some additional options, for Mac OSX (10.11 or newer), there's this program: Compositor (check on current pricing).

A review from Jan., 2018 of LaTeX and WYSIWYG/WYSIWYM editors is found here.

Wikipedia has produced a comparison of editors (see the "Integrated viewer" table column).

1

I made a simple python script that automates recompiling based on file change. Github link.

All you have to do is run script with specified arguments:

python compiler.py [file_path] [output_directory]

More info can be found in readme file.

4
  • 1
    Welcome to TeX.SE! Can you explain your answer please better? How is that script to be used? Can you show the tested tex code here and your script? And the resulr as screenshot? Then your answer gets valid, otherwise it is more or less only a link,
    – Mensch
    Mar 28, 2019 at 19:19
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review Mar 28, 2019 at 19:42
  • 1
    @samcarter It is a simple wait loop that has a heavy requirement to install python if you don't already have it (it would possibly be better to use perl as supplied with Tex live) It will run one pass pdfLaTeX on the file you are editing which would probably foul a number of editors and likely knock out synctex etc. also uses a "build" folder which would likely bork bibtex glossaries makeindex etc. (good idea but very much alpha status) you could chron arara or latexmk for better results
    – user170109
    Mar 28, 2019 at 23:55
  • @KJO Thanks for the analysis! Mar 29, 2019 at 0:25
0

The problem of fast document update is TeX core&idea itself -- TeX is interpreted programming language by design.

So the problem is thru-whole-document dependency: every section depends on data with all previous sections defined by sequential document execution from start to end.

Thus for the thing you want is it required totally rewrite TeX core from scratch. Technically TeX render engine must track source file changes, split them into isolated pieces, store them in in-memory graph database may be, with dependency info, and every time you save, it must rebuild resulting preview in update manner, walking thru dependency graph.

Another thing is an endpoint of preview output: component shows ready page must support direct partial update using some sort of bitblt overlay, can be done on modern GPU at a hardware level.

Or we should look on JavaScript: DOM document model in a browser by design support dynamic partial update, and a lot of effort was done by browser authors to make this subsystem totally fast. So some render server runs locally on your workstation, can update document elements view in parallel and update DOM in a browser via an async interface.

Is anybody here has some experience on DIY TeX core (it will be fun to do it on in-browser JavaScript), but it will be a huge effort on coding, and especially on making it compatible with a large set of packages.

As the starting point to write your fast render engine I can point on this large manual on implementing (La)TeX:

The Computer Science of TeX and LaTeX (c) Victor Eijkhout

can be downloaded in .PDF https://bitbucket.org/VictorEijkhout/the-science-of-tex-and-latex/downloads/TeXLaTeXcourse.pdf

Going thru this manual it is possible to write some limited version of TeX compatible with your documents and chosen render system able to update content on the fly part by part. For example, you can write fast latex2html converter, like I'm trying to do it now (package in Debian Linux not works for me especially with lstlistings).

If you want to be really fast, avoid using any disk files as much as possible, and do all thing in RAM only, using some GUI toolkit for render output (Qt,wxWidgets,..): flex/bison generated parser (or some other syntax parser library, like PLY for Python) able to parse from text strings.

7
  • It will be great to make Google Docs -like online editor able to render widely used data formats like GNU .Plots, source codes formatters for well known programming languages, vectors graphics (.svg), and so on. But it require few well-skilled JS/web programmers able to rewrite TeX core Sep 18, 2017 at 4:23
  • Overleaf is terribly slow on documents larger then few pages -- it just run something like pdflatex on from any mainstream Linux distro Sep 18, 2017 at 4:24
  • 2
    How is this an answer to the question?
    – Johannes_B
    Sep 18, 2017 at 5:36
  • 1
    Contentwise this is more of a comment/starting point to an answer, but not a complete answer. There are considerable ideas though. Hencewhy I won't recommend deletion. Please try to make your answer a little bit more concrete (and insert a few missing articles : ) Like your call for collaboration!
    – Ruben
    Sep 18, 2017 at 9:14
  • Ruben: you are asking for working (prototipe) TeX realization as answer, so it needs large effort on coding and to be extra specialist in core TeX itself. I'm going to do this like system later, but can't post link to my project -- this will be considered an advertisement by SE/SO rules (I already had a similar case with link on PLAI book proposed as link to ful l answer) Sep 18, 2017 at 12:41
0

Vim with VimTeX + AutoSave plugin

Usage: On a TeX file, press \ll to start the compiler. Every time the TeX file is saved, the PDF will be automatically recompiled.

Optionally run :AutoSaveToggle to save the file every time the buffer changes.

Of course this uses latexmk under the hood (other build systems are also supported, check the README).

Personally, because normally each compilation takes more than 0.1 second (although there are a few ways to speed it up slightly), I think it's inconvenient to recompile on every keystroke. Instead, when I need recompile, I just explicitly save the file.

You must log in to answer this question.

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