views:

274

answers:

4
+3  Q: 

"Publish" to pdf

Using Matlab, I would like to create a pdf document summarizing the results of several experiments. Ideally, I'd have one page per experiment with 2 multi-panel figures and a bit of text.

I thought that publish.m would be the way to go, however, publishing to pdf does not support inserting page breaks, and I can neither control the figure quality (which is rather bad), nor the figure size (which means that 2 figures take up the entire page), nor could I stuff the text into headers/footers.

How else could I create a multipage pdf with some control over the layout from within Matlab?

A: 

MathWorks do a Report Generator toolbox that allows you to style your output - basically it is a much fancier version of the publish function.

Richie Cotton
+4  A: 

There exists the Matlab Report Generator Toolbox, which can do that very easy. Of course it costs some money.

You could try to write out some markup text from Matlab and then convert it to PDF using some other tools. Possible converters:

  • Write out LaTeX, then use PdfLaTeX to generate PDF
  • Write out reStructuredText, then use Python docutils to generate PDF
  • Write out DocBook XML, then use any DocBook to PDF converter
  • Write out HTML, then print it with your browser or OpenOffice to PDF.

If you don't want this, have a look at the Matlab documentation. You can specify the image size/resolution for published figures and I think there exists the possibilty to insert line breaks.

Wolfgang Ulmer
Thank you for your suggestions. Of course, the Report Generator Toolbox happens to be one of those I don't have access to.Unfortunately, it is not possible to specify image size/resolution and line breaks for publishing to pdf, as I mentioned in the question (a look at the Matlab documentation and a service request confirmed that). I guess it is going to be a toss-up between learning enough LaTeX to make a nice document, or using publishing to HTML to make something fast.
Jonas
What about using preformatted text (Cell > Insert Text Markup > Preformatted Text) in M-File comments ? It supports line breaks.To be able to define image sizes, first use the `print -dpng` command (see `help print`) to create a separate image file, then include the generated file in your published M-file (<<imgfilename.png>>). You can specify options to define the size of the printed image.
Wolfgang Ulmer
Sorry, I meant 'page breaks', not 'line breaks'.
Jonas
A: 

If you really want control over pdf generation, take a look at the iText Java PDF library -- you can use Java libraries fairly easily from MATLAB.

Jason S
A: 

In the end I went with LaTeX, since it gives documents of much higher quality than if I went via HTML.

Unfortunately, publish.m is rather limited even when it comes to publishing to LaTeX. For example, if you add multiple figures inside a loop, it is not possible to set page breaks, and adjusting figure sizes to get exactly N figures onto a page is very hard.

Therefore, I wrote a function to directly write the LaTeX file (using export_fig from the file exchange to save the figures), and another one to compile to pdf. This way, I can easily generate LaTeX files and I have a lot of power over formatting.

Jonas