10
$\begingroup$

Ok, I've never used the formatting language Latex. I would like to install an editor on my PC so that I could write/format answers on my PC rather than multiple edits on the site. I obviously want mhchem as well. So what to use?

Also it would be nice if the editor had a preview window rather than having to see the output in a second pass.

EDIT - I guess what I'd really like is what might be called "split screen" viewing. Really three options. (1) Full screen markup, (2) Half screen markup & half screen preview, and (3) Full screen preview

$\endgroup$
11
$\begingroup$

As an alternative, if you do not want to write pure $\rm\LaTeX{}$, but rather Markdown plus MathJax with mhchem enabled, it requires more work but is possible.

There are three fully-featured user-friendly popular text editors at this point: Sublime Text, Atom, and Visual Studio Code. All have syntax highlighting and package managers with Markdown plugins for editing and previewing. It's the mhchem bit that takes work. I am unfamiliar with Sublime, but I can give instructions for Atom and VS Code. A big advantage of this approach in addition to being independent from $\rm\LaTeX{}$ is that it should be OS-agnostic. For example, I figured this out on my Mac, but it will also work on Windows and Linux.

VS Code

  1. On the left-hand side, click the Extensions button:

enter image description here

This will bring up the package manager. Search for "markdown" using the top text box, then install "Markdown Preview Enhanced".

  1. Assuming you have a Markdown document opened, right-click and turn on preview:

enter image description here

The result should look like this:

enter image description here

  1. Open up the Command Palette under the View menu, and click on "Open MathJax Config":

enter image description here

  1. Add the latest version of mhchem to the end of the extensions, then save. As of this writing, it is 'https://cdnjs.cloudflare.com/ajax/libs/mathjax-mhchem/3.2.0/mhchem.js'.

enter image description here

  1. Open the user preferences, scroll down to "Markdown Preview Enhanced", expand the section, scroll down more to markdown-preview-enhanced.mathRenderingOption, click the little pencil on the left-hand fringe, and switch from KaTeX to MathJax.

enter image description here

This inline equation should now render properly: $\ce{2H2 + O2 -> 2H2O}$.

enter image description here

Atom

  1. Open the preferences, click on "Install", type "markdown" in the search box, hit enter, and install markdown-preview-enhanced:

enter image description here

  1. This is the same plugin as for VS Code. Click Settings, scroll down, and change the math rendering from KaTeX to MathJax:

enter image description here

and it looks like things should work.

$\endgroup$
  • $\begingroup$ This does not answer the question, but for anyone who would like instructions on how I set up Emacs to do something similar, please comment. $\endgroup$ – pentavalentcarbon Dec 17 '17 at 19:13
  • $\begingroup$ Do any of these have "split screen" viewing? Really three options. (1) Full screen markup, (2) Half screen markup & half screen preview, and (3) Full screen preview. $\endgroup$ – MaxW Dec 17 '17 at 19:42
  • 3
    $\begingroup$ Yes, all of them do, you can see it in some of the screenshots, in particular the 2nd and 3rd ones. They default to split screen. I closed the split pane because it gets tight on my small laptop. You can also drag tabs between panes. $\endgroup$ – pentavalentcarbon Dec 17 '17 at 20:06
  • $\begingroup$ Given Martin's point about MathJax ≠ LaTeX, with VS Code or Atom is it possible to "name" a profile? In other words have a name for one set of specifications (a profile) which does MathJax & mhchem and another named for a profile which does real LaTeX? $\endgroup$ – MaxW Dec 18 '17 at 12:58
  • 2
    $\begingroup$ What you are thinking of is handled in a specific way across most text editors meant for programming. When you open an *.md file, the editor will recognize it as being Markdown, highlight it appropriately for Markdown, and turn on any Markdown plugins you have installed. In the VS Code screenshots, you can see it changing from "Markdown" to "JavaScript" to "JSON with Comments" in the bottom right as I switch between files in different languages. When you open a *.tex file, if you have a plugin installed, it will be recognized as $\rm\LaTeX{}$ and appropriate plugins loaded. $\endgroup$ – pentavalentcarbon Dec 18 '17 at 15:23
  • 1
    $\begingroup$ Here is the out-of-box experience with VS Code and $\rm\LaTeX{}$. Atom is identical. Both require a plugin to recognize $\rm\LaTeX{}$ as something other than plain text. But, plugins are available to compile and preview from the editor, much like TeXShop, Kile, or other TeX editors. $\endgroup$ – pentavalentcarbon Dec 18 '17 at 15:25
  • $\begingroup$ I wish I knew about this trick with mhchem.js and vscode earlier :( Great insight post about great editor (vscode). $\endgroup$ – andselisk Dec 19 '17 at 9:20
  • 1
    $\begingroup$ @andselisk Would you mind if I posted the VS Code part of this as an answer there? $\endgroup$ – pentavalentcarbon Dec 19 '17 at 14:26
  • $\begingroup$ @pentavalentcarbon Yes, please! I'd really love to get that question answered:) $\endgroup$ – andselisk Dec 19 '17 at 14:33
  • $\begingroup$ The MathJax configuration shown above does load the "legacy" mhchem.js. Chemistry.SE makes use of a newer version. $\endgroup$ – mhchem Dec 19 '17 at 15:21
  • $\begingroup$ @mhchem I will try and update the image at some point, especially if someone tells me exactly what to do, because I know nothing about VS Code and my Emacs config doesn't have this problem. $\endgroup$ – pentavalentcarbon Dec 19 '17 at 15:36
  • $\begingroup$ MathJax v2.7.2 ships mhchem 3.2.0 and uses it by default. The vscode extension is, however, still at v2.7.1. To properly load mhchem 3.2.0 from cdnjs, you need to set specify a custom extension path called [mhchem] to match the location of mhchem.js, cf. docs.mathjax.org/en/latest/options/…. $\endgroup$ – Peter Krautzberger Dec 20 '17 at 8:53
7
$\begingroup$

Check out MiK$\rm{\TeX}$ or alternatives such as $\rm\TeX$ Live, or any of the others detailed at The $\rm\LaTeX$ Project. All the distributions include and support $\rm\TeX$ and $\rm\LaTeX$.

I do most of my work on Linux machines ($\rm\TeX$ Live or te$\rm\TeX$), but use Mac$\rm\TeX$ on my Mac.

I use MiK$\rm\TeX$ on Windows 10, and through the package manager you can install mhchem (and a zillion other packages). There is a document previewer called yap (Yet Another Previewer) that comes bundled with MiK$\rm\TeX$ which will allow you to preview your typeset documents, which you will create using an editor called $\rm\TeX$works. The workflow is typeset in $\rm\TeX$works, view using yap. You can then copy and paste the source code into the box here on Chem.SE.

The help documentation for MiK$\rm\TeX$ is quite extensive and the project is, like the others mentioned above, well-maintained.

Note that you will have to install several packages using the package manager in order to get mhchem to work. The following $\rm\LaTeX$ source, compiled with the pdf$\rm\LaTeX$ interpreter in $\rm\TeX$works, is an example of what you might want:

\documentclass[10pt, a4paper]{article} \usepackage[version=4]{mhchem} \begin{document} $\ce{NaOH -> Na+ + OH-}$ \end{document}

which produces

$$\ce{NaOH -> Na+ + OH-}$$

in the pop-up window.

$\endgroup$
  • $\begingroup$ Is YAP used after the markup file is created? Possible to use two windows and "refresh" view of markup file? $\endgroup$ – MaxW Dec 17 '17 at 18:30
  • 1
    $\begingroup$ YAP is used after the source is compiled, yes. But actually, it's easier than that it: Open TeXworks and choose pdfTeX from the drop-down menu, then enter some text, such as $\int_{0}^{1}$\bye. Click the green arrow button in the upper left corner, and the typeset output pops up in another window. Add/remove/alter text and just hit the button again and the output window is updated. $\endgroup$ – Todd Minehardt Dec 17 '17 at 18:38
  • 1
    $\begingroup$ Super fantastic. I'll give it a try. Now to learn my 87th text editor. ;-) $\endgroup$ – MaxW Dec 17 '17 at 18:40
  • 3
    $\begingroup$ General Warning: MathJax =/= LaTeX! And a very precise warning: The latex-mhchem is significantly different from the mathjax-mhchem. See for example on tex.sx. Also note that MathJax, while using latex syntax, is off-toppic on TeX - LaTeX. $\endgroup$ – Martin - マーチン Dec 18 '17 at 4:30
  • 1
    $\begingroup$ Ok - thanks for the heads-up. $\endgroup$ – Todd Minehardt Dec 18 '17 at 5:40
5
$\begingroup$

This is not really an answer to the question, rather than an alternative to installing an extra text editor.

There is one thing that cannot be emphasised enough, MathJax ≠ LaTeX. In this very special case it is very important to know that mhchem in the LaTeX library is significantly different from mhchem.js as the MathJax extension. This is demonstrated well with this Q&A on TeX.SX. So if you do not want to learn LaTeX for yourself, but only want to use the LaTeX syntax to write maths on this site, I suggest you follow pentavalentcarbon's advice, or use the following alternative.

I have found it challenging to write answers using a lot of MathJax in the past, and while I have been training my LaTeX for more than a decade now, the implementation we have at hand here is quite limited, and it requires relearning. Unfortunately, the preview can be very annoying, compare here, but can be very helpful in seeing what you have created in the meantime. However, scrolling up and down is a nuisance. Therefore I am using a user script from stackapps.com with the tampermonkey extension on chrome:

Side By Side Editing

This userscript adds a button to the editor toolbar ('Toggle Side-By-Side Editing') so you can view the preview and markdown side by side when asking or answering a question or when editing an existing question or answer.

While it sometimes does not sync up completely as the maths code tends to be a lot longer than the final rendering, it is certainly helpful for most purposes, as you see what you type while you type. Here is an example screenshot.

screenshot side-by-side editing

$\endgroup$
  • 1
    $\begingroup$ This argument, while true, is generally a non-issue for 99% of users, and I feel is overblown. If you are doing simple editing with math or \ce{}, there should not be any surprises. Replacing \pu{} with siunitx macros is easy because of the good documentation. Granted, tables are missing from our implementation, not only from MathJax, but because we don't have GitHub-flavored Markdown... $\endgroup$ – pentavalentcarbon Dec 18 '17 at 15:48
  • 2
    $\begingroup$ I find converting si to pu rather tedious, especially doing it the other way around. Learning LaTeX only for this site simply is overkill... IMO $\endgroup$ – Martin - マーチン Dec 18 '17 at 16:00
  • 2
    $\begingroup$ Ah yes, tables in the MathJax way—every one should give me seven years in hell … $\endgroup$ – Jan Dec 18 '17 at 16:44

You must log in to answer this question.

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