An initial commit
Hi, I just made this website. It’s built with Wowchemy, using the Hugo academic-pages template. This is my first post, partly by way of testing, partly by way of introduction. I’ll be sharing physics thoughts here as a series of blog-esque posts. Some lazy ones may just be embedded tweets. Some will be typed like I’m doing now, with a button at the top to download as a pdf (recommended instead of just savng the page as a pdf). If you want to comment on any posts, I may implement that here at some point, but probably the best thing is to comment on twitter, where I’ll also be sharing my posts. I’ll link to the corresponding tweet from the post to make it easier :)
In case it’s of interest: I’ve been desperately looking for the easiest way to write posts in latex and then put them online. For a while I tried just embedding pdfs. To do that, there are things like viewerJS, Mozilla’s pdf.js, and various others, but the simplest thing I found was to just use the google drive pdf viewer. All I needed to do was paste something like the following little bit of html directly into the index.md file of a post:
<iframe src="https://drive.google.com/viewerng/
viewer?embedded=true&url=https://www.danielduffy.org/post/integration/integration.pdf"
style = "height: 300px;
left: 0;
position: absolute;
width: 100%;" >
The results of that were still kind of clunky, even for the user reading the post, so instead I’m converted my .tex to markdown using the amazing command line tool pandoc. The one-line command is as simple as
pandoc -f latex -t markdown integration.tex -s -o integration_md.txt
Then I just copy the contents of integration_md.txt directly into my post’s index.md file. That gets me 90% of the way there, though there’s always some further tweaking required. So far, the fix-it-in-post manual tweaks I have to make seem to be:
- I couldn’t get clever labelling and referencing of figures to work, so I just remove all that, and do it entirely by hand, i.e. manually writing captions like Fig. 1: …, and then manually writing (fig. 1) in the text etc.
- Labelling, tagging and referencing of equations. Each equation you want to reference should get something like
\label{eq:energy}\tag{1}
, and then it can be referenced in the text with\ref{eq:energy}
. If the equation is an aligned environment, the label and tag should go near the end like this:\end{aligned}\label{eq:energy}\tag{1}$$
. Alternatively, it seems (e.g. https://math.meta.stackexchange.com/questions/3514/using-the-align-environment) you can just replace{aligned}
with{align}
, and then label each line of the align as you would in standard Latex, though now each\label{}
should come also with a\tag{}
immediately after it. - The
\\
used to move to a new line in environments like align, pmatrix, cases etc needs to be replaced with\\\\
. - Some underscores and asterisks need escaping with a backslash. I’m not sure why some do and some don’t.
- The
\\
at end of a paragraph will be converted to\
by pandoc, but that single backslash doesn’t seem to give reliable results. So I remove it and just hit enter a couple times in its place. You can also add the HTML<br>
to force a line break anywhere desired, which I often do to prevent weird things like a full stop at the start of a line. - I need to replace all the small math spaces
\,
with\\,
, and any\{
with\\{
. - Something about
\left|
and similar doesn’t seem to work at all on my laptop (though does on my phone!!??). The only thing I could come up with that worked is to replace with\rule[-7pt]{0.4pt}{20pt}
or similar. Disgusting hack but oh well. To get $\frac{\mathrm{d}y}{\mathrm{d}x}\rule[-7pt]{0.4pt}{20pt}\genfrac{}{}{0pt}{0}{}{\scriptstyle{x=0}}$ I use a further hack:\frac{\mathrm{d}y}{\mathrm{d}x}\rule[-7pt]{0.4pt}{20pt}\genfrac{}{}{0pt}{0}{}{\scriptstyle{x=0}}
. - Sometimes the images are too big, so you have to replace
![sketch](sketch.png)
with<img src="sketch.png" style = "width: 50%;" >
. - Image captions have to be added manually. I use italics for this, which is done by putting text between underscores. Note, you seem to need a blank line between the
<img ...>
html and the caption text for this to work, and also no math can be between the underscores, so each little piece of text between math has to be done individually. Lame. \bm
needs to be replaced with (the inferior)\mathbf
or\boldsymbol
.- Latex tables (text macros) should be replaced with latex arrays (math macros), so that MathJax (which handles math macros) can do its thing. Best to just use arrays instead of tables as a habit in the first place probably!
\tiny
is a text macro so is no good for MathJax. A corollary is that something like\text{\tiny 2D}}
in an equation should be replaced with\scriptscriptstyle{\mathrm{2D}}
.- Citations might have to be done manually, so I think in your latex if you write
\cite{me}
pandoc will turn that into[@me]
, but that doesn’t seem to do anything by itself, so I turn that into[^7]
or whatever instead. I.e. I just do the citing with footnotes. - Doing numbered lists seems to work better starting each line with
1\.
or whatever, rather than just1.
that seems to prevent you from controlling the spacing between entries easily.
Anyway those tweaks aren’t too strenuous, and it all seems to work ok (plus https://github.com/tomduck/pandoc-xnos would probably fix some of these things automatically if I could be bothered to use it). Some other people have been doing the same kind of thing so I’m not the first to take this approach of getting latex on a website. You could always just type pure MathJax, but that’s potentially much more limiting; I want to use the full power of LaTex and all the syntax I’m used to, and then stick the results online. It really seems like that shouldn’t be this hard. Even the above solution is not ideal; this is definitely not a solved problem yet imo!
If you liked this post, please subscribe to this blog to be notified via email about future posts, and/or follow me on twitter.