Convert Jupyter notebook to PDF - pdflatex not found on PATH - macos

I'm trying to download my Jupyter notebook as a PDF from the web interface by going to:
File -> Download as -> PDF via LaTeX
However, I get this error:
nbconvert failed: pdflatex not found on PATH
I have both pandoc and MacTex installed. Additionally, in the terminal the pdflatex is set.
$ which pdflatex
/Library/TeX/Distributions/.DefaultTeX/Contents/Programs/texbin/pdflatex
I'm running on Mac OS X El Capitan using Jupyter 4.2.0 with Python 2.7.11

Print it to pdf using your browser (ctrl+p). It is simple and the "you print what you see" approach is great to share a reports/analysis with people that do not code or use the jupyter enviroment. Not publication ready by any means but gets the job done. Just make sure your plots and figures are not on interactive mode otherwise they will not be displayed (set them to %matplotlib inline).
I always had trouble with exporting my jupyter nb to pdf through latex. Quick search and you see that A LOT of people do. I could get some stuff worked out but the formatting was lackluster with code and plots not displayed the way I wanted. I eventually accepted that the jupyter notebook could not produce "publish-ready" pdfs easily. When I want that, I generate plots/figures/code on jupyter and call them on a latex file.
You may want to hide some of your code from the pdf, set the resolution of your plots and add some extensions to improve your jupyter documents.
If you really want to make your publications from inside jupyter, this tutorial has some great tips.

I've had a lot of luck exporting to HTML instead of pdf. HTML is similarly viewable by any non-developers in your organization, assuming they have a browser, and you can make use of some excellent tools like toc2, which gives your viewers a table of contents so they can stay oriented with what they are reading. You can also link to specific sections using the "#" symbol to do header links. Similarly, HTML supports interactive plotting like those available through plotly, so that end-users can zoom into graphs and other figures. Encourage you to give it a shot. Example code with nbconvert below:
jupyter nbconvert --to html --template toc2 --TemplateExporter.exclude_input=True "<path-to-ipynb>"
If its really necessary to have a pdf, you can then open your html in Chrome or Firefox and print to pdf that way. Hope it helps!

Related

Where are copy-pasted images stored in Jupyter Notebook?

This is very similar to this question but it hasn't been answered.
I launched a Jupyter server from PyCharm. I created a screenshot, and copy and pasted it into a Jupyter Notebook. The image wasn't otherwise saved. In Jupyter Notebook, the image appears like this: ![image.png](attachment:image.png) and I can see the image on the Jupyter server, but I can't see the image in the notebook file in PyCharm. I can't find where the image.png file is stored. I looked through the folder that the notebook is in, and I used the file explorer to check if the image is anywhere on my computer.
Does Jupyter Notebook store the copy-pasted image as a file? and if yes, where?
This answer here fills in some information on what is going on.
When you pasted it into the markdown cell, it got encoded as an attachment in base64 in the cell information for that cell.
If you view the underlying code for the notebook in a text editor you should see encoded data. (You may wish to make a test notebook, separate from the one you care about, and add an image to test that after you save the edited new notebook.)
And so there is no separate saved file.

How to extend RStudio MathJax to include extensions in "live" notebooks?

One of the answers to the StackOverflow question below gives a way of knitting an html page which can use mhchem.js to typeset basic chemistry notation.
How to access MathJax extensions (like siunitx) from Rmarkdown via Pandoc & Knitr?
How can I modify RStudio MathJax to make this rendering happen live in the edited document? Preferably, this extension would just be enabled for all RStudio notebook files for all users of the RStudio Server installation. How can this be accomplished?
I found out this is already built-in once I tell it the magic word:
$$
\require{mhchem}
\ce{H + H -> H_2}
$$
See the MathJax docs:
http://docs.mathjax.org/en/latest/input/tex/extensions/mhchem.html

Convert Markdown to pdf with images on mac

This is driving me crazy. I have a jupyter notebook with images and I'm trying to convert it to a pdf on my mac. I've installed pandoc and macTex, but when I try to convert it to pdf the images disappear. Also the formatting for my tables gets messed up. I've tried saving it as a markdown and converting it, but I get the same problem. If I convert to html the images disappear but the table formatting is correct. I've also tried converting it in the terminal with nbconvert, but the images still disappeared. And I tried converting the markdown file with rstudio, but still the images disappeared. I've tried two versions of the code to reference images. The versions are below, both display fine in the jupyter notebook but the first one throws an error and the second one the images disappear. I've googled around, it seems to be a common issue but I'm not seeing a lot of solutions. I really can't believe this is this difficult. Any solution is greatly appreciated.
code with errors:
![Stars_Boxplot](Stars_Boxplot.PNG)
code disappears when rendered:
<img src="Stars_Boxplot.PNG">
Update Solution:
![Stars_Boxplot](/Users/Desktop///Project Research//Stars_Boxplot.PNG)
The issue was it had to be an absolute reference and I had a space in my file path.

Batch convert Mac iWork files to PDF on the command line

I'm trying to batch convert a bunch of assorted iWork files (Numbers, Pages, Keynote) to PDF on the command line.
I've been trying cups-filter but there's no MIME type filter for the iWork types. I then looked into using qlmanage to generate the preview image and use that, but this doesn't seem to work for multi file Keynote documents as they generate as HTML rather than PDF.
Any suggestions? I'd rather not resort to AppleScript.
I created an .applescript script that converts all .pages files within a folder to .docx. .pdf support can be easily added. In pages2docx.applescript you just need to replace Microsoft Word with PDF.
Here's what I ended up going with, since I really wanted to avoid, AppleScript.
When saving an iWork document there's a "Include Preview In Document" checkbox. Checking this creates a "QuickLook/Preview.pdf" inside the iWork document bundle (which is actually a zip file). Luckily I had this checked for most of the zip files, so it was simply a case of unzipping to NSTemporaryDirectory and grabbing that file.
For those that didn't I put together a script to run qlmanage to create the document preview. For some that creates the PDF, for others it creates an HTML file. You can then use http://code.google.com/p/wkhtmltopdf/ to convert this HTML to a PDF.
Well... you need something that
understand the iWork file formats,
can render the documents to then create the PDF.
Unless you want to re-invent the iWork suite... Sounds simpler to just tell the iWork apps what you want from them.
You would do that via the Scripting Bridge
I would use Applescript, but perhaps you can use Ruby and Python with the Scripting Bridge to accomplish what you need
With Scripting Bridge, RubyCocoa and PyObjC scripts can do what AppleScript scripts can do: control scriptable applications and exchange data with them.
I haven't used the Scripting Bridge in a while, but I believe you can tell applications to print documents. And any application that can print in OS X can send it to PDF instead.
Here are a couple of commands to help those who want to get this working without much thought. It worked for me with a ppt file.
Make sure to get wkhtmltopdf from here.
qlmanage -p -o /tmp /path/of/file.ppt
wkhtmltopdf /tmp/file.ppt.qlpreview/Preview.html /output/to/file.pdf
You may have to fiddle with sizes if you want the original pages to stay consistent, for the ppt I was using the following parameters did the job:
wkhtmltopdf --page-width 200 --page-height 145 Preview.html file.pdf
Edit: I have written a Python script to do a batch conversion. Hopefully people can contribute to make it more robust:
https://github.com/matthewfitch23/DocToPdf

Miktex on Windows Vista

I have some problems with Miktex installed on Windows Vista Business SP1/32 bit. I use miktex 2.7, ghostscript, and texniccenter 1 beta 7.50. When I compile a document with the following profiles: Latex=>DVI, Latex=>PDF everything works fine; the system crashes when I compile with profiles Latex=>PS and Latex=>PS=>PDF. The error is reported into a window that states: "Dvi-to-Postscript converter has stopped working". What can I do? I need Latex=>PS=>PDF to include my images into the final PDF.
Thanks in advance,
Yet another LaTeX user
If everything you need is images, you could still compile directly to PDF. You only need to have an image in PNG or JPG format, and use the following code:
%in the document preamble
\usepackage{graphicx}
%in the document, in the place where you want to put your image
\includegraphics{image_filename_without_extension}
When the image is a PNG or JPG file (there are some more, I don't remember which ones ATM), you can compile the file with pdfLaTeX, but not with the normal LaTeX (i.e. you can produce a PDF, but not DVI or PS).
Of course normally, if everything works fine, it's nice to have one copy of the image in EPS, and another in, say, PNG -- this way you can compile easily both to PDF, and to PS.
Hope that helps.
Thanks for reply. I have solved the problem: the dvi crashed because I have installed Miktex with the User Account Control enabled. I have disabled it, reinstalled and now it's working (with UAC still disabled).

Resources