11
$\begingroup$

I am using Mathematica 8. I want to label the axes of figure in "Times" font.

Plot[Sin[z], {z, -2 Pi, 2 Pi}, Frame -> True, 
 FrameLabel -> {"z", "a(z)"}, 
 LabelStyle -> Directive[FontSize -> 20, FontFamily -> "Times"]]

And the plot is enter image description here

However in Miktex, when I am using FontStyle, Times then z is different. So I want to replace enter image description here by enter image description here

the second one is the default z appearing pdf generarted from .tex file in math mode. So what extra information should be given to Mathematica, besides "Times".

$\endgroup$
  • $\begingroup$ The second Z is Times Italic. To get that in Mathematica add the option FontSlant-> Italic to your Plot function call. $\endgroup$ – Sjoerd C. de Vries Mar 2 '15 at 19:33
  • $\begingroup$ did not resolve the problem for me in Mathematica 8 $\endgroup$ – zenith Mar 2 '15 at 20:19
  • $\begingroup$ You mean you did not get the italic version of the font? $\endgroup$ – Sjoerd C. de Vries Mar 2 '15 at 20:56
  • $\begingroup$ @ Sjoerd Now its been resolved. I made a mistake previously as i added FontSlant-> Italic in Label style. So that it italicized all the tikz labels also. Moreover, the required font was not visible in Mathematica 8.0, but when I saved it in .eps format and seen in the .pdf generated through Miktex it was visible. Thank you $\endgroup$ – zenith Mar 2 '15 at 21:12
  • $\begingroup$ If you can wait a couple of days, I'll have an answer for this. It's an accident that I'm doing this at the same time when you asked the question. I didn't even see your question until now. $\endgroup$ – Szabolcs Mar 3 '15 at 0:15
16
$\begingroup$

You can match formatting between Mathematica figures and LaTeX using a small package I just wrote for using LaTeX-snippets in Mathematica: MaTeX.

Here's an example:

<<MaTeX`

Plot[Sin[z], {z, -2 Pi, 2 Pi},
 Frame -> True, FrameStyle -> BlackFrame,
 FrameLabel -> (MaTeX[#, Magnification -> 20/12] &) /@ {"z", "a(z) = \\sin z"},
 BaseStyle -> {FontFamily -> "Latin Modern Roman", FontSize -> 20}]

Additionally, I used the Latin Modern font for tick labels to fully match the "LaTeX look", and set the frame to be black instead of gray.

Mathematica graphics

If you prefer the Times font, we can do that too:

SetOptions[MaTeX, "Preamble" -> {"\\usepackage{amsmath,amssymb}", "\\usepackage{txfonts}"}];

Plot[Sin[z], {z, -2 Pi, 2 Pi}, Frame -> True, 
 FrameStyle -> BlackFrame, 
 FrameLabel -> (MaTeX[#, Magnification -> 20/12] &) /@ {"z", "a(z) = \\sin z"}, 
 BaseStyle -> {FontFamily -> "Times", FontSize -> 20}]

Mathematica graphics

$\endgroup$
  • 1
    $\begingroup$ Today I also wanted to ask a similar question, but just when I had almost given up hope that a nice, clean solution would exist, I came across your answer and your easy-to-use package "MaTeX." Many thanks for developing such a convenient package (and for clearly documenting the steps needed to make it work)! $\endgroup$ – TMM Mar 30 '15 at 23:35
  • $\begingroup$ @TMM I'm glad you find it useful. Feel free to email me if you have any comments or suggestions. $\endgroup$ – Szabolcs Mar 31 '15 at 2:04
  • $\begingroup$ Actually there's one question I had, which may also be useful to readers of this website: is it possible to automate the MaTeXing further? i.e. Write something like MaTeX[Plot[x, {x,0,1}]] and it automatically TeXifies the tick labels on the axes? Alternatively, is there a convenient way to TeXify automatically generated ticks on axes? Many thanks again! $\endgroup$ – TMM Apr 1 '15 at 2:05
  • $\begingroup$ @TMM For ticks, I would recommend simply using the Latin Modern font instead of MaTeX. While theoretically it should be possible to auto-process tick labels, there are many obstacle ... Option 1: Use FullGraphics to render the axes and ticks as graphics objects, then go from there. FullGraphics has stayed neglected since Mma6 and it's practically unusable in v10. Option 2: Get the tick labels using AbsoluteOptions, then process those. This works better, but not perfectly. Often, what AbsoluteOptions returns is quite a bit different from the automatically rendered ticks. $\endgroup$ – Szabolcs Apr 1 '15 at 18:15
  • 1
    $\begingroup$ @axsvl77 Just use \text, not \textrm. This is shown in several examples in the documentation. Suggestions on how to improve the documentation are always welcome, but keep in mind that just adding more information and making it longer is not going to help—people already don't read it. $\endgroup$ – Szabolcs Jul 12 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.