Mathematica uses a screen resolution of 72 dpi. For post-processing figures I use Corel, which conveniently allows me to use metric units (mm) for positioning and resizing figures. Say, I want to export a figure exactly 80mm wide. I would use a snippet of code like this:
mm=72/25.4;
myplot=Plot[Sin[x],{x,0,10},BaseStyle->{6},ImageSize->{80mm,40mm},
ImagePadding->{{8mm,2mm},{6mm,2mm}},AspectRatio->32/70,Frame->True];
Export["myplot.pdf",myplot]
The problem is that 80mm is 226.772 points. So Mathematica exports a PDF with a rounded width of 227 points i.e. 80.081mm. Tweaking options such as "ScreenResolution" or passing options to Export such as ImageResolution does not seem to change anything, as Mathematica invariably behaves such, that one pixel at 100% magnification is 1/72 of an inch. This can become a problem when, for example, I have to arrange several such figures into a grid in Corel and lead to minor misalignments.
So is 1/72 of an inch the one and only resolution that Mathematica can use for these purposes or is there a way to work accurately in metric units?
Edit to follow up links given in comments:
How to set image DPI shows a neat example when exporting to a raster format. Some investigation shows that
Export["figure.tiff", Show[g, ImageSize -> 720.25],ImageResolution -> 72]
creates a tiff file 720 pixels wide (obviously, there must be an integer number of pixels). Increasing the image resolution four-fold helps:
Export["figure.tiff", Show[g, ImageSize -> 720.25],ImageResolution -> 288]
This results in a tiff file 2881 pixels wide (not 2880 or 2884). 2881/288*25.4=254.089mm. However (and sorry for not mentioning this explicitly before), I would like to export to a vector format, such as PDF. So I try the following code:
Export["figure.pdf", Show[g, ImageSize -> 720.25]]
As usual, Mathematica does the export to the precision of a printer point, equal to 1/72 of an inch, but this time gives a PDF not 720 "pixels" wide (254mm), like it was for the TIFF file, but rounds up. The PDF is 254.353mm, or 10+1/72 of an inch - 721 printer points. If I increase the resolution:
Export["figure.pdf", Show[g, ImageSize -> 720.25],ImageResolution -> 288]
the width of the exported file is still 254.353mm, not the desired/expected 254.089mm, as was with the TIFF image. This little inacurracy is not adressed in the linked questions, I'm afraid.
Further investigation: Specifically for my problem there is a workaround I have found:
g=Plot[Sin[x],{x,0,10},Background->None,ImageSize->720.25,Epilog->{Directive[Green,Opacity[.2]],Rectangle[ImageScaled[{0,0},ImageScaled[{1,1}]]]}]
Export["myplot.pdf",g,Background->None]
This kind of code still yields a PDF which is 721/72 inches wide (rather than the desired 720.25), however the semi-transparent green rectangle overlaying the graph will be exactly 720.25/72 inches wide. Upon importing such a PDF into Corel it will ignore the absent background and claim to observe an image with the desired width of 254.089mm. This works well for the purposes of aligning figures, as Corel now sees the correct size, but is still somewhat unsatisfactory, as now I have to manually delete the background of every figure I export if I actually want the figure to have a transparent background. Also this highlights the problem if the figure is opened in a PDF viewer - around the edges of the otherwise green image there will be small white margins visible. I would be grateful, if someone can confirm, that there is no better way, or better yet, suggest a way to override Mathematica's default assumption that the value passed to ImageSize is the width of the image in units of 1/72 of an inch (why can't I change this arbitrary number to 1/100 or 1/254 or 1mm).
Export["Z:\\Temp\\figure.tiff", Show[g, ImageSize -> 720.25], ImageResolution -> 72]
generates a tiff file 720 pixels wide, butExport["Z:\\Temp\\figure.tiff", Show[g, ImageSize -> 720.25], ImageResolution -> 288]
gives a tiff file not 2880, but 2881 pixels wide, as would be expected for that extra quarter in ImageSize. When recalculating the print size from pixels (2881) and resolution (288), I then correctly get 254.089mm or 10+1/288 of an inch. If I change the filename to figure.pdf, I get an image 254.359mm wide. $\endgroup$