# How do I prevent fonts sizes and line weights from scaling in exported graphics?

It's common to export graphics from Mathematica that are subsequently scaled to various sizes that cannot (at least not conveniently) be anticipated. This is problematic in cases where (as is common) fonts and line weights need to fixed (e.g. throughout a document or presentation, or simply to prevent a figure from looking ridiculous).

For example, if the default options for fonts and line weights are satisfactory, then

Plot[{Sin[x], Cos[5 x]}, {x, 0, 2 Pi}]


will produce a figure with correct font sizes an line weights

and scaling this figure within Mathematica (e.g. by dragging the resize frame) will preserve these font sizes and line weights:

However, if I export the original graphic in a resizable format (i.e., choosing "Save Graphic As..." and specifying a PDF "Vector Representation", which, as far as I can tell, is the only form suitable for subsequent resizing), the fonts and line weights scale with the graphic

which is not the desired result.

Is there a way to generate and export graphics so that font sizes and line weights are preserved when the exported graphic is resized?

-
You might take a look at the ImageSize option (e.g. for Show[] and ImageResolution for export, though I only used the latter one for PNG images, it might also work for the font size and line with in eps exports. –  Ronny Dec 9 '12 at 19:16
I think the point of PDF as an export format is that it doesn't change any aspect of the original graphics, whether line art or text size and positioning. However, if you open a PDF graphic up in something like Adobe Illustrator, you'll be able to resize text independently of graphics (because the font sizing commands affect only the text). –  cormullion Dec 9 '12 at 19:28
@cormullion: That depend on what "change" means. In the context of my scenario, the behavior I'm trying to overcome is that resizing does change font size and line weight. I'd have thought that PDF had a way to say "make this x points wherever it appears", but it might not, which would surprise me. –  raxacoricofallapatorius Dec 9 '12 at 20:06
I think, the reason for the "change" you're expierincing is, that the scaling (via drag) you are performing, does change the (absolute) size of the pdf, but neither the size in cm with respect to the resolution. Hence your - say doubled in size -- image does take the double space in the PDF, while inside getting rendered with respect to old size/resolution. Hence the bigger line width and font size. –  Ronny Dec 9 '12 at 21:28
I don't think you can do it in PDF except maybe using Javascript in Adobe Reader (which won't work in other readers). With SVG it could also be done using Javascript if you plan to display the graphic in a browser (e.g., by catching the onresize event). Of course that goes into off-topic territory for this site. –  Jens Dec 9 '12 at 22:56

The main point is, that you can change two things, the resolution of the image (which is for example the option ImageResolution in dpi but only for PNG and not for EPS) and the actual size of the image using ImageSize. That one is a little tricky, because it is given in dpi with respect to 72 dpi.

A = Plot[{Sin[x], Cos[5 x]}, {x, 0, 2 Pi}]


to an image of size 24 cm (and hence the standard font size of 10pt gets quite small and so does the line width with respect to the complete image)

B = Show[A, ImageSize -> 24/2.54*72]


where the calculations are due to conversion into in and the typical Resolution of 72 dpi. To export something like that you can use

Export["~/Desktop/A.eps", B]


or for PNG you can further specify the dpi the image should then have using

Export["~/Desktop/A.png", B, ImageResolution -> 150]


to get 150 dpi. That does than look lie the following

That way you have a nice way to control the font size of your graphic and the actual size of the result (for later usage e.g. in LaTeX).

edit: Oh. I overlooked your PDF point and red eps. But it works for PDF, too.

-