MATLAB Community

MATLAB, community & more

Publishing made easy with publish configurations 11

Posted by admin,

The publish function has been around since R14 and has proved useful for a number of things, to include demonstrating concepts, creating reports and generating blogs. In R2008a we’ve made it easier to fit publishing into your work flow, by introducing publish configurations, younger brother to run configurations (introduced in R2007b).

The most significant change is that you can now have multiple sets of publish options associated with a single file – previously there was a single set of global publish options. This added flexibility allows you to more easily publish different files with different options and even publish the same file with different options.

To get aquatinted with this new feature, let’s look at how our very own Loren of Loren on the Art of MATLAB uses publish configurations in her workflow.

Loren’s Workflow:

After composing the first draft of her entry in the MATLAB Editor, Loren likes to check the spelling and grammar of the file. The easiest way to do this, is to publish the document to Word format, and then open the published output in Word. It’s important to publish the document first, as this ensures that she’s viewing the same content that the reader will be seeing.

Once Loren is happy with the entry, it’s time to publish it to HTML. One of the restrictions when publishing her blog is the width of the images – too wide an image causes scroll bars and layout problems, so she likes to restrict image width to 500 pixels.

Here’s are the steps Loren follows in order to take advantage of this new feature:

Draft Phase – Publishing to Word

Step 1: Once the draft is ready for spelling and grammar checking, open the configuration editor by clicking the drop down arrow next to the publish button and select Edit Publish Configurations for [your_file.m]:

This automatically creates a publish configuration with the name of your file (‘foo’ in the figure above). You can also specify input to the function you’re publishing, as I’ve done above.

Notice that there are two sets of Publish Settings that ship with MATLAB: Factory Default and User Default. Every new publish configuration you create, will use the User Default settings, which you can change if you’d like (see the doc for how to do this). But you can also create custom sets of settings. In the next two steps we’ll create a custom set of publish settings that we can use now and in the future each time we want to spell check and grammar check our work.

Step 2: Change the Output file format to doc:

Notice that a dot is shown next to the Output file format setting, indicating that our settings have deviated from the User Default settings.

Step 3: Now click Save As… in the configuration editor and type Word for the Settings name in the Save Publish Settings As dialog. When you’ve finished typing the name click Save:

This creates a new set of publish settings that will be used in the current publish configuration. These new settings will also be available to use in other publish configurations via the Publish Settings combo box:

Step 4: Click Publish in the configuration editor and review the document.

Blog Phase – Publishing to HTML:

OK…the spelling and grammar have been checked and we’re ready to upload the blog entry to the web. Next we’ll open up the configuration editor again, create a new publish configuration and create another set of reusable publish options for blog posts.

Step 5: Press the add button in the configuration editor and select Publish Configuration:

This creates a new publish configuration associated with your file, which is named ‘foo_2’ in the example above. This configuration uses the User Default publish settings, and because the default output format is html, we don’t have to change this setting.

Step 6: Now change the Max image width (pixels) to 500:

Finally, press Save As… in the configuration editor and type Blog for the Settings name and click Save (as we did above).

Step 7: Click Publish and upload to the web!

End State:

Loren’s MATLAB file now has two publish configurations, one using the Word publish settings, and one using the Blog publish settings. Each time Loren creates a blog entry, she can create a publish configuration for her MATLAB file and select the publish settings appropriate for her current task (spelling and grammar checking or getting ready to upload to the web).

MATLAB saves all the configurations for every file, as well as the publish settings that are used within the configuration. This makes it easy for Loren to consistently publish a file with the same settings.

Give Publish Configurations a Try!

Your work flow and ultimate product may be different from Loren’s, but the publish configurations can reap the same work flow benefits for you. Let us know how you use this feature!


Comments are closed.

11 CommentsOldest to Newest

naor replied on : 1 of 11
I know this isn't a common feature of development environments, but I have often wished for some type of spelling check in the matlab editor. Maybe not "as you type", but during publishing?
Ken replied on : 2 of 11
Hi Naor, I too have wished for such a feature - mainly for spell checking comments. There is a feature request for this, which I'll add your comments to. -Ken
Stefan replied on : 3 of 11
When publishing to LaTex, is there a possibility to replace the Matlab default settings. For example to change the \documentclass tag or to include some header standard text using \input ?
Michael Katz replied on : 4 of 11
Yes. When a M-file is published to LaTex, we create a XML-file , which is then transformed to the TEX-file using a stylesheet. This stylesheet is in $MATLABROOT\toolbox\matlab\codetools\private\mxdom2latex.xsl. I recommend copying that XSL-file locally, modifying it to suit your needs, and then specify that as the stylesheet in Publish Configurations.
Richard Johnson replied on : 5 of 11
Publish is a wonderful feature, and I recommend it frequently to my students. Publishing a function (without execution) is very convenient for generating easy to read documentation. Of course there are issues. To get a nice looking published result from a function, you seem to have to put the header comment block above the function line. (See the example in the R2008a documentation.) This is not harmful but goes against many years of practice. Since MATLAB can recognize a function and even extract its name, it seems that functions could be handled more smoothly.
Matthew Simoneau replied on : 6 of 11
We considered making a special rule for M-file help when publishing functions, but decided against it for this first release. It's under consideration for the future, though. Thanks for your feedback.
Mark replied on : 8 of 11
I currently don't have Microsoft Office on my mac that I am running MatLab on. I am a student and so free OpenOffice is a lot more appealing than paying Bill his blood money. I bring this up because when I publish my code and results I don't have the option to output as a .doc, which does make sense because I don't have word on my computer. I was just wondering if there is a round-a-bout way to get that option or even publishing to an .ods format or something equally as easy to edit. Thank you so much for your time and help. Mark
Mike replied on : 9 of 11
@Mark, There is not, but you can try publishing to html and then open that page in your editor and re-save in the native format.
William replied on : 10 of 11
It looks like this example was done on a mac. How do I get the .doc option on a mac? I only have .pdf, .html, .xml, and .latex. I am on lion, with matlab R2010b and Word 2011. Thanks