semilogx font problem

I am having a font problem with semilogx, usetex=true and
font.family:sans-serif. The xticks are using a serif font. These
lines are enough to recreate the problem on my machine.

t=arange(0,1,0.01)
y=sin(2*pi*t)
figure(10)
semilogx(t,y)
ylabel('Mag.')
xlabel('Time (sec.)')
savefig('test.png')

The figure is attached.

Thanks,

Ryan

test.png

You might be able to do something like this in LogFormatterMathtext:

if rcParams['text.usetex']:
        if not isDecade and self.labelOnlyBase: s = ''
        elif not isDecade: s = '%d$^\textnormal{%.2f}$'% (b, fx)
        else: s = '%d^\textnormal{%d}$'% (b, self.nearest_long(fx))

I dont have time to test it, I'm running out the door.

Darren

···

On Wednesday 12 April 2006 17:13, Ryan Krauss wrote:

I am having a font problem with semilogx, usetex=true and
font.family:sans-serif. The xticks are using a serif font. These
lines are enough to recreate the problem on my machine.

t=arange(0,1,0.01)
y=sin(2*pi*t)
figure(10)
semilogx(t,y)
ylabel('Mag.')
xlabel('Time (sec.)')
savefig('test.png')

That almost works except that the exponents are still serif and they
are gigantic (I had to add an extra slash on '\\textnormal'. The 10's
look good though. Here is my __call__ in LogFormatterMathtext:

def __call__(self, x, pos=None):
        'Return the format for tick val x at position pos'
        self.verify_intervals()

        b = self._base
        # only label the decades
        fx = math.log(x)/math.log(b)
        isDecade = self.is_decade(fx)

        if rcParams['text.usetex']:
            if not isDecade and self.labelOnlyBase: s = ''
            elif not isDecade: s = '%d$^\\textnormal{%.2f}$'% (b, fx)
            else: s = '%d^\\textnormal{%d}$'% (b, self.nearest_long(fx))

        else:
            if not isDecade and self.labelOnlyBase: s = ''
            elif not isDecade: s = '$%d^{%.2f}$'% (b, fx)
            else: s = '$%d^{%d}$'% (b, self.nearest_long(fx))

        return s

How is the font being set in Latex? Where is it set?

Thanks,

Ryan

···

On 4/12/06, Darren Dale <dd55@...143...> wrote:

On Wednesday 12 April 2006 17:13, Ryan Krauss wrote:
> I am having a font problem with semilogx, usetex=true and
> font.family:sans-serif. The xticks are using a serif font. These
> lines are enough to recreate the problem on my machine.
>
> t=arange(0,1,0.01)
> y=sin(2*pi*t)
> figure(10)
> semilogx(t,y)
> ylabel('Mag.')
> xlabel('Time (sec.)')
> savefig('test.png')

You might be able to do something like this in LogFormatterMathtext:

if rcParams['text.usetex']:
        if not isDecade and self.labelOnlyBase: s = ''
        elif not isDecade: s = '%d$^\textnormal{%.2f}$'% (b, fx)
        else: s = '%d^\textnormal{%d}$'% (b, self.nearest_long(fx))

I dont have time to test it, I'm running out the door.

Darren

Apparently this is not a trivial Latex problem. People have written
packages to solve it. I don't know if this solves more problems than
it causes, but with helvet+sfmath I get nice results with:

...
\usepackage{helvet}
\usepackage{sfmath}
\begin{document}
$10^{-1}$
\end{document}

sfmath is not a popular package (I don't think), so requiring it as a
prerequisite is probably not a good idea. Is it worth re-opening the
discussion of a user specified header file for Latex?

Latex book, I don't think we will get san-serif math fonts without a
lot of work (or a special package).

Ryan

···

From my poking around and what I have read on the internet and in my

On 4/12/06, Ryan Krauss <ryanlists@...149...> wrote:

That almost works except that the exponents are still serif and they
are gigantic (I had to add an extra slash on '\\textnormal'. The 10's
look good though. Here is my __call__ in LogFormatterMathtext:

def __call__(self, x, pos=None):
        'Return the format for tick val x at position pos'
        self.verify_intervals()

        b = self._base
        # only label the decades
        fx = math.log(x)/math.log(b)
        isDecade = self.is_decade(fx)

        if rcParams['text.usetex']:
            if not isDecade and self.labelOnlyBase: s = ''
            elif not isDecade: s = '%d$^\\textnormal{%.2f}$'% (b, fx)
            else: s = '%d^\\textnormal{%d}$'% (b, self.nearest_long(fx))

        else:
            if not isDecade and self.labelOnlyBase: s = ''
            elif not isDecade: s = '$%d^{%.2f}$'% (b, fx)
            else: s = '$%d^{%d}$'% (b, self.nearest_long(fx))

        return s

How is the font being set in Latex? Where is it set?

Thanks,

Ryan

On 4/12/06, Darren Dale <dd55@...143...> wrote:
> On Wednesday 12 April 2006 17:13, Ryan Krauss wrote:
> > I am having a font problem with semilogx, usetex=true and
> > font.family:sans-serif. The xticks are using a serif font. These
> > lines are enough to recreate the problem on my machine.
> >
> > t=arange(0,1,0.01)
> > y=sin(2*pi*t)
> > figure(10)
> > semilogx(t,y)
> > ylabel('Mag.')
> > xlabel('Time (sec.)')
> > savefig('test.png')
>
> You might be able to do something like this in LogFormatterMathtext:
>
> if rcParams['text.usetex']:
> if not isDecade and self.labelOnlyBase: s = ''
> elif not isDecade: s = '%d$^\textnormal{%.2f}$'% (b, fx)
> else: s = '%d^\textnormal{%d}$'% (b, self.nearest_long(fx))
>
> I dont have time to test it, I'm running out the door.
>
> Darren
>

Apparently this is not a trivial Latex problem. People have written
packages to solve it. I don't know if this solves more problems than
it causes, but with helvet+sfmath I get nice results with:

...
\usepackage{helvet}
\usepackage{sfmath}
\begin{document}
$10^{-1}$
\end{document}

sfmath is not a popular package (I don't think), so requiring it as a
prerequisite is probably not a good idea. Is it worth re-opening the
discussion of a user specified header file for Latex?

I'm hesitant, because people will try to do things that won't work and then
post here asking for help. I was hoping that usetex was getting to the point
that I wouldnt have to give it so much attention... but it might be the
easiest solution to this problem.

From my poking around and what I have read on the internet and in my
Latex book, I don't think we will get san-serif math fonts without a
lot of work (or a special package).

That is my impression as well. I dont have time to look into this more
tonight, I have to do my taxes.

Darren

···

On Wednesday 12 April 2006 6:34 pm, you wrote:

I can understand not wanting to create a maintenance and support mess.

What do you think about a secret option to add a package (or two)?

I am pretty much o.k. with this as a compromise:

if rcParams['text.usetex']:
            if not isDecade and self.labelOnlyBase: s = ''
            elif not isDecade: s = '%d$^{%.2f}$'% (b, fx)
            else: s = '%d^{%d}$'% (b, self.nearest_long(fx))

The exponents have serifs, but the 10's don't. You have to look
pretty closely to see the serifs on the exponents.

Ryan

···

On 4/12/06, Darren Dale <dd55@...143...> wrote:

On Wednesday 12 April 2006 6:34 pm, you wrote:
> Apparently this is not a trivial Latex problem. People have written
> packages to solve it. I don't know if this solves more problems than
> it causes, but with helvet+sfmath I get nice results with:
>
> ...
> \usepackage{helvet}
> \usepackage{sfmath}
> \begin{document}
> $10^{-1}$
> \end{document}
>
> sfmath is not a popular package (I don't think), so requiring it as a
> prerequisite is probably not a good idea. Is it worth re-opening the
> discussion of a user specified header file for Latex?

I'm hesitant, because people will try to do things that won't work and then
post here asking for help. I was hoping that usetex was getting to the point
that I wouldnt have to give it so much attention... but it might be the
easiest solution to this problem.

> From my poking around and what I have read on the internet and in my
> Latex book, I don't think we will get san-serif math fonts without a
> lot of work (or a special package).

That is my impression as well. I dont have time to look into this more
tonight, I have to do my taxes.

Darren