I am running Mathematica 11.0, and am trying to create a bar chart to insert into a LaTeX document; since the document is in LaTeX, I would like the look of the chart to be in line with this, and so have been trying to use the MaTeX package to achieve this. Having set it all up however, when I run the code, the axis labels/numbers etc aren't changed into the computer modern font as I thought they would be. Here is my code:


BarChart[{-10, -5, 10, 50}, 
 AxesLabel -> {X-Axis, Y-Axis}, 
 ChartLabels -> {"1", "2", "3", "4"}, ChartStyle -> {"Pastel"}, 
 BaseStyle -> {FontFamily -> "Latin Modern Roman", FontSize -> 16}]

and here is what it returns (ignore the exact placing of labels, I'll fix that once I've got MaTeX working): enter image description here Confused about why it wasn't working, I thought I'd try to run one of the examples given on the website to check my install of MaTeX was ok. The code given was:

texStyle = {FontFamily -> "Latin Modern Roman", FontSize -> 12};
ContourPlot[x^2 + y^4 == 1, {x, -1.2, 1.2}, {y, -1.2, 1.2},
 BaseStyle -> texStyle,
 Epilog -> {
     Arrow[{{0.1, 0.3}, {0.5, 0.80}}],
     Inset[MaTeX["x^2+y^4=1", Magnification -> 2], {0.1, 0.3}, Scaled[{0.5, 1}]]

and on the website returned this: enter image description here however when run on my version of Mathematica, returned this (ignore the sizing of the maths in the middle; this is just because I sized up the image before exporting it): enter image description here What confuses me is that the axis labels in my version have not changed, as they didn't for my bar chart, even though the maths in the middle still renders fine (which suggests that MaTeX is correctly installed and working).

Any help is greatly appreciated! :)

  • $\begingroup$ Should not your axes labels be strings? AxesLabel -> {X-Axis, Y-Axis} and I would try using texStyle = {FontFamily -> "Latin Modern Roman", FontSize -> 16} instead of BaseStyle -> {FontFamily -> "Latin Modern Roman", FontSize -> 16} to see if it does what you want. $\endgroup$
    – Nasser
    Oct 28 '17 at 18:28
  • $\begingroup$ @Nasser as in they should be typed AxesLabel ->{"X-Axis","Y-Axis"}? $\endgroup$ Oct 28 '17 at 18:32
  • 1
    $\begingroup$ yes. They should be strings. But you did not use string for your axis labels looking at your post above. Mathematica just used X - Axis as some expression. Since you had no value for X and no value for Axis it left it as is. But this is wrong. It should be string. $\endgroup$
    – Nasser
    Oct 28 '17 at 18:33
  • $\begingroup$ @Nasser Thanks very much I have changed them to strings; would I then use AxesStyle -> texStyle or another command? $\endgroup$ Oct 28 '17 at 18:36

The first block of code you show,

BarChart[{-10, -5, 10, 50}, AxesLabel -> {"X-Axis", "Y-Axis"}, 
 ChartLabels -> {"1", "2", "3", "4"}, ChartStyle -> {"Pastel"}, 
 BaseStyle -> {FontFamily -> "Latin Modern Roman", FontSize -> 16}]

does not use MaTeX and does not need MaTeX. All you need is to install the Latin Modern Roman font, and specify it with FontFamily.

Where this gets tricky is that the name you must use with FontFamily is different for each operating system. I use "Latin Modern Roman" in the MaTeX documentation because that's the correct form on OS X (my platform of choice). However, on Windows it is called something different. "LM Roman 12" if memory serves.

Please go to Format -> Show Fonts to reveal the font list, and check the correct name of the font on your operating system.

Another note: You are linking to MaTeX's website, but the bulk of the documentation is part of the package, and can be accessed through the Documentation Center (Mathematica's Help menu). The MaTeX tutorial included in the main documentation does mention this problem:

enter image description here


I am not sure if you want to change Axes labels to Latex only or also change the ticks. According to MaTeX web site, to also change ticks to Latex, one needs to manually typeset them to Latex.

I do not know why texStyle is not making this change automatically.

But this works. It means you have to type set them manually using MaTeX command on each item you want to show as Latex

<< MaTeX`

lb1 = MaTeX["\\text{X-Axis}", Magnification -> 1.25];
lb2 = MaTeX["\\text{Y-Axis}", Magnification -> 1.25];

BarChart[{-10, -5, 10, 50}, 
 AxesLabel -> {lb1, lb2},
 ChartLabels -> {MaTeX[#, Magnification -> 1.3] & /@ {"1", "2", "3", "4"}}, 
 ChartStyle -> {"Pastel"},
 PlotRangePadding -> Scaled[.05]

Mathematica graphics

Although for some reason, the font is not sharp.

  • $\begingroup$ Thank you very much this is definitely a large step in the right direction; I’m going to leave the question open for a few more days to see if anyone can fix the fuzzy text/tick labels $\endgroup$ Oct 28 '17 at 19:59

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.