Discussion:
LaTeX Interpreter and Helvetica
(too old to reply)
Martin Kaufmann
2006-01-16 03:26:32 UTC
Permalink
Hi!

I'm using the LaTeX interpreter to have access to special math symbols
(e.g. \sqrt) in my labels. Since for all the other text Helvetica is
used, I'd like to use that font for the LaTeX text as well. Does anyone
know if that's possible? The following line uses Computer Modern Sans
Serif (cmss) on my system (I attached a complete example at the
bottom):

xlabel('\textsf{This is my label}', 'Interpreter', 'latex');

I also tried something like

xlabel('{\fontfamily{phv}\selectfont This is my label}', 'Interpreter',
'latex');

which didn't work.

Any ideas?

BTW, is there a list of supported LaTeX commands?

Thanks for your help!

Cheers,

Martin

------- example.m ----
x=0:0.1:3;
y=x.^2;
plot(x,y);
xlabel('\textsf{This is my x-label}', 'Interpreter', 'latex');
ylabel('This is my y-label');
text(1.15,0.3,'This is more text');
Rachel van Ooteghem
2006-03-28 09:43:43 UTC
Permalink
Post by Martin Kaufmann
Hi!
I'm using the LaTeX interpreter to have access to special math
symbols
(e.g. \sqrt) in my labels. Since for all the other text Helvetica is
used, I'd like to use that font for the LaTeX text as well. Does anyone
know if that's possible? The following line uses Computer Modern Sans
Serif (cmss) on my system (I attached a complete example at the
xlabel('\textsf{This is my label}', 'Interpreter', 'latex');
I also tried something like
xlabel('{\fontfamily{phv}\selectfont This is my label}',
'Interpreter',
'latex');
which didn't work.
Any ideas?
BTW, is there a list of supported LaTeX commands?
Thanks for your help!
Cheers,
Martin
------- example.m ----
x=0:0.1:3;
y=x.^2;
plot(x,y);
xlabel('\textsf{This is my x-label}', 'Interpreter', 'latex');
ylabel('This is my y-label');
text(1.15,0.3,'This is more text');
Hi Martin,

The easiest way to do this is to set the font for the current Matlab
session to Helvetica for all axes and text items, e.g, in Matlab:

fontname = 'Helvetica';
set(0,'defaultaxesfontname',fontname);
set(0,'defaulttextfontname',fontname);

The same routine can also be used to increase the font size:
fontsize = 12;
set(0,'defaultaxesfontsize',fontsize);
set(0,'defaulttextfontsize',fontsize);

A complete list of all LateX characters in Matlab is found at:
<http://www.mathworks.com/access/helpdesk/help/techdoc/ref/text_props.html#String>

With kind regards,

Rachel.
Brian
2009-01-08 19:32:01 UTC
Permalink
Post by Rachel van Ooteghem
Post by Martin Kaufmann
Hi!
I'm using the LaTeX interpreter to have access to special math symbols
(e.g. \sqrt) in my labels. Since for all the other text Helvetica is
used, I'd like to use that font for the LaTeX text as well. Does anyone
know if that's possible? The following line uses Computer Modern Sans
Serif (cmss) on my system (I attached a complete example at the
xlabel('\textsf{This is my label}', 'Interpreter', 'latex');
I also tried something like
xlabel('{\fontfamily{phv}\selectfont This is my label}',
'Interpreter',
'latex');
which didn't work.
Any ideas?
BTW, is there a list of supported LaTeX commands?
Thanks for your help!
Cheers,
Martin
------- example.m ----
x=0:0.1:3;
y=x.^2;
plot(x,y);
xlabel('\textsf{This is my x-label}', 'Interpreter', 'latex');
ylabel('This is my y-label');
text(1.15,0.3,'This is more text');
Hi Martin,
The easiest way to do this is to set the font for the current Matlab
fontname = 'Helvetica';
set(0,'defaultaxesfontname',fontname);
set(0,'defaulttextfontname',fontname);
fontsize = 12;
set(0,'defaultaxesfontsize',fontsize);
set(0,'defaulttextfontsize',fontsize);
<http://www.mathworks.com/access/helpdesk/help/techdoc/ref/text_props.html#String>
With kind regards,
Rachel.
I am having the same problem as Martin, but I don't think that Rachel's post really provides a solution to the problem. As far as I can tell, setting the default font to Helvetica does not influence the font used by the 'latex' interpreter. Also, the list of LaTeX characters given at the link above only seems to include those characters recognized by the 'tex' interpreter. I have had some success with commands like:

text('Interpreter','latex', ...
'String', '{\bfseries\itshape\sffamily This is bold italic sans-serif}', ...
'Position', [0.5 0.5])

In practice, however, this sequence only really recognizes the last command, which was \sffamily, yielding a non-italic serif font. Otherwise, the text would come out in italics as a result of the \itshape command. Beyond all of that, I have found no way to get a Helvetica font to work with the 'latex' interpreter. Does anyone know if this is possible in Matlab? Thank you for your help,

- Brian
Doug Schwarz
2009-01-09 00:51:55 UTC
Permalink
In article <gk5kbh$24g$***@fred.mathworks.com>,
"Brian " <***@hotmail.com> wrote:

[snip]
Post by Brian
I am having the same problem as Martin, but I don't think that Rachel's post
really provides a solution to the problem. As far as I can tell, setting the
default font to Helvetica does not influence the font used by the 'latex'
interpreter.
Correct.
Post by Brian
Also, the list of LaTeX characters given at the link above only
seems to include those characters recognized by the 'tex' interpreter.
Also correct.
Post by Brian
text('Interpreter','latex', ...
'String', '{\bfseries\itshape\sffamily This is bold italic
sans-serif}', ...
'Position', [0.5 0.5])
In practice, however, this sequence only really recognizes the last command,
which was \sffamily, yielding a non-italic serif font. Otherwise, the text
would come out in italics as a result of the \itshape command. Beyond all of
that, I have found no way to get a Helvetica font to work with the 'latex'
interpreter. Does anyone know if this is possible in Matlab? Thank you for
your help,
- Brian
It is possible to use Helvetica in LaTeX, but not in MATLAB. The place
in a .tex file where you would specify it seems to be hard coded into
MATLAB and I haven't found any way to access it, though I have tried.

So your best bet is probably to do what you have already done. I prefer
the \textsf, \textit and \textbf commands, but they do the same thing.
The reason you can't get slanted, bold text is that typographically it's
not really a good thing to do and so no one built a slanted, bold
version of the sans serif font.
--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.
Lee Bassett
2009-07-17 11:52:01 UTC
Permalink
An alternate 'solution' to this problem is to replace the other fonts (e.g. Helvetica) in the figure with Computer Modern equivalents - in fact this is often the preferred behaviour when the figure is intended for a LaTeX document typeset with the CM fonts. It's no good just to select one of the actual CM fonts (cmr10, etc.) as these do not have standard key bindings so you will not see what you type. But a nice solution is to install the unicode versions of these fonts, which are available from http://canopus.iacp.dvo.ru/~panov/cm-unicode/.

Once these are installed, setting the axes 'FontName' property to 'CMU Serif Roman' will use the CM unicode roman font to render all the text in the axes. Including a line set(0,'DefaultAxesFontName','CMU Serif Roman') in your startup.m file will set this as the default for all the figures you create.

-Lee
Post by Doug Schwarz
[snip]
Post by Brian
I am having the same problem as Martin, but I don't think that Rachel's post
really provides a solution to the problem. As far as I can tell, setting the
default font to Helvetica does not influence the font used by the 'latex'
interpreter.
Correct.
Post by Brian
Also, the list of LaTeX characters given at the link above only
seems to include those characters recognized by the 'tex' interpreter.
Also correct.
Post by Brian
text('Interpreter','latex', ...
'String', '{\bfseries\itshape\sffamily This is bold italic
sans-serif}', ...
'Position', [0.5 0.5])
In practice, however, this sequence only really recognizes the last command,
which was \sffamily, yielding a non-italic serif font. Otherwise, the text
would come out in italics as a result of the \itshape command. Beyond all of
that, I have found no way to get a Helvetica font to work with the 'latex'
interpreter. Does anyone know if this is possible in Matlab? Thank you for
your help,
- Brian
It is possible to use Helvetica in LaTeX, but not in MATLAB. The place
in a .tex file where you would specify it seems to be hard coded into
MATLAB and I haven't found any way to access it, though I have tried.
So your best bet is probably to do what you have already done. I prefer
the \textsf, \textit and \textbf commands, but they do the same thing.
The reason you can't get slanted, bold text is that typographically it's
not really a good thing to do and so no one built a slanted, bold
version of the sans serif font.
--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.
HanaKaze
2015-04-15 18:47:47 UTC
Permalink
Worked perfect!! Thank you Lee!!
Post by Lee Bassett
An alternate 'solution' to this problem is to replace the other fonts (e.g. Helvetica) in the figure with Computer Modern equivalents - in fact this is often the preferred behaviour when the figure is intended for a LaTeX document typeset with the CM fonts. It's no good just to select one of the actual CM fonts (cmr10, etc.) as these do not have standard key bindings so you will not see what you type. But a nice solution is to install the unicode versions of these fonts, which are available from http://canopus.iacp.dvo.ru/~panov/cm-unicode/.
Once these are installed, setting the axes 'FontName' property to 'CMU Serif Roman' will use the CM unicode roman font to render all the text in the axes. Including a line set(0,'DefaultAxesFontName','CMU Serif Roman') in your startup.m file will set this as the default for all the figures you create.
-Lee
Post by Doug Schwarz
[snip]
Post by Brian
I am having the same problem as Martin, but I don't think that Rachel's post
really provides a solution to the problem. As far as I can tell, setting the
default font to Helvetica does not influence the font used by the 'latex'
interpreter.
Correct.
Post by Brian
Also, the list of LaTeX characters given at the link above only
seems to include those characters recognized by the 'tex' interpreter.
Also correct.
Post by Brian
text('Interpreter','latex', ...
'String', '{\bfseries\itshape\sffamily This is bold italic
sans-serif}', ...
'Position', [0.5 0.5])
In practice, however, this sequence only really recognizes the last command,
which was \sffamily, yielding a non-italic serif font. Otherwise, the text
would come out in italics as a result of the \itshape command. Beyond all of
that, I have found no way to get a Helvetica font to work with the 'latex'
interpreter. Does anyone know if this is possible in Matlab? Thank you for
your help,
- Brian
It is possible to use Helvetica in LaTeX, but not in MATLAB. The place
in a .tex file where you would specify it seems to be hard coded into
MATLAB and I haven't found any way to access it, though I have tried.
So your best bet is probably to do what you have already done. I prefer
the \textsf, \textit and \textbf commands, but they do the same thing.
The reason you can't get slanted, bold text is that typographically it's
not really a good thing to do and so no one built a slanted, bold
version of the sans serif font.
--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.
Juan Pontes
2009-08-16 10:52:01 UTC
Permalink
Hi there,

I think the problem of defining a specific font such as helvetica within the latex interpreter is related to the non-existance of its font definition file (.fd) within the matlab distribution. In fact if you do the following

\fontfamily{cmr}\fontseries{b}\selectfont test $\sqrt{z}$
\fontfamily{cmtt}\fontseries{n}\selectfont test

(Note that this wouldn't work: \fontfamily{cmtt}\selectfont test )

you can in fact use different font families. However defining the "phv" family (Adobe Helvetica) results in the default fonttype "cmr" because it can't find the ot1phv.fd file. I tried using the file provided from my Miktex installation, but then I couldn't see the text anymore, probably because of an error. I suspect that the file I used is from a different version/distribution. Therefore, I guess the task at hand is actually finding a font definition file for helvetica that works with the latex version used by matlab.

Cheers
Juan Pontes
Post by Doug Schwarz
[snip]
Post by Brian
I am having the same problem as Martin, but I don't think that Rachel's post
really provides a solution to the problem. As far as I can tell, setting the
default font to Helvetica does not influence the font used by the 'latex'
interpreter.
Correct.
Post by Brian
Also, the list of LaTeX characters given at the link above only
seems to include those characters recognized by the 'tex' interpreter.
Also correct.
Post by Brian
text('Interpreter','latex', ...
'String', '{\bfseries\itshape\sffamily This is bold italic
sans-serif}', ...
'Position', [0.5 0.5])
In practice, however, this sequence only really recognizes the last command,
which was \sffamily, yielding a non-italic serif font. Otherwise, the text
would come out in italics as a result of the \itshape command. Beyond all of
that, I have found no way to get a Helvetica font to work with the 'latex'
interpreter. Does anyone know if this is possible in Matlab? Thank you for
your help,
- Brian
It is possible to use Helvetica in LaTeX, but not in MATLAB. The place
in a .tex file where you would specify it seems to be hard coded into
MATLAB and I haven't found any way to access it, though I have tried.
So your best bet is probably to do what you have already done. I prefer
the \textsf, \textit and \textbf commands, but they do the same thing.
The reason you can't get slanted, bold text is that typographically it's
not really a good thing to do and so no one built a slanted, bold
version of the sans serif font.
--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.
Ugur Goktolga
2015-07-28 09:49:03 UTC
Permalink
Post by Martin Kaufmann
Hi!
I'm using the LaTeX interpreter to have access to special math symbols
(e.g. \sqrt) in my labels. Since for all the other text Helvetica is
used, I'd like to use that font for the LaTeX text as well. Does anyone
know if that's possible? The following line uses Computer Modern Sans
Serif (cmss) on my system (I attached a complete example at the
xlabel('\textsf{This is my label}', 'Interpreter', 'latex');
I also tried something like
xlabel('{\fontfamily{phv}\selectfont This is my label}', 'Interpreter',
'latex');
which didn't work.
Any ideas?
BTW, is there a list of supported LaTeX commands?
Thanks for your help!
Cheers,
Martin
------- example.m ----
x=0:0.1:3;
y=x.^2;
plot(x,y);
xlabel('\textsf{This is my x-label}', 'Interpreter', 'latex');
ylabel('This is my y-label');
text(1.15,0.3,'This is more text');
If you want to use LaTeX interpreter of MATLAB, create .eps figures, and get the desired font (like Helvetica) instead of Computer Modern fonts, I think I’ve finally found a solution. I actually saw it here: http://stackoverflow.com/questions/11212172/latex-fonts-in-matlab But I needed to scroll down a little bit and read the answers which did not get any upvote.

Anyways, the trick is to open the resulting .eps file with a text editor and replace cm fonts with Helvetica or whatever you want. For example, change the following lines:

%%IncludeResource: font mwa_cmr10
/mwa_cmr10 /WindowsLatin1Encoding 120 FMSR
with the following:

%%IncludeResource: font Helvetica
/Helvetica /WindowsLatin1Encoding 120 FMSR
I hope this helps to whomever googles this problem.
Juan Guerrero
2017-04-26 07:23:03 UTC
Permalink
I have just written a tutorial on this for Matlab versions 2015b and 2016b. Feel free to download it at: http://isa.uniovi.es/~guerrero/FontExample/FontExampleFiles.zip

Regards.

Loading...