6

While producing Latex output from Matlab, I used the following in command window:

publish('filename.m',struct('format','latex','showCode',false,  ...
        'maxWidth',3,'outputDir','Desktop'));

The latex file produced has graphics width always 4in. Even though I
changed the maxWidth to 5, 6, 1000 etc, the graphics width remains always the same: 4in.

How can I vary the graphics width in latex directly from Matlab?

Shai
  • 111,146
  • 38
  • 238
  • 371

1 Answers1

2

It looks like maxWidth option affects only pixel images, like png, bmp etc. It affects actual image size, so with maxWidth set to 3, you will get images with maximum 3 pixel width. It's not controlled by format itself, like width argument in html or latex. PUBLISH function uses XML as the intermediate format and I believe this is the problem of current XML schema design.

With latex format PUBLISH by default uses epsc2 print driver and produces vector image in EPS format. So maxWidth is simply ignored. If you use ...'imageFormat','png',... in publish call you notice that the size of output png file changes in accordance with maxWidth. Anyway the size of the image in tex document will be 4in (with bad image resolution in case of low maxWidth) as set in the default stylesheet for latex.

Looks like there is no way to change this behavior in PUBLISH.

You can modify the xml stylesheet (matlabroot/toolbox/matlab/codetools/private/mxdoom2latex.xls).

Check for those lines:

<xsl:template match="img">
\includegraphics [width=4in]{<xsl:value-of select="@src"/>}
</xsl:template>

Copy this file, modify and specify the new file with stylesheet option.

Or simply change the width argument in the output .tex file(s).

yuk
  • 19,098
  • 13
  • 68
  • 99