xlabel('\\textbf\{toto\}') # bad
xlabel(r'\\textbf\{toto\}') # ok
xlabel('\\bf\{toto\}') # bad
xlabel(r'\\bf\{toto\}') # ok
And this bring to the second question, I would like to create the xlabel with latex stuf inside somewhere in my script:
label='\\textrm\{test\}\_2'
but that can't work:
xlabel(label) # bad
How to tell that I want the "r" before the chains to have TeX working like expected?
I think you have much to gain and nothing to lose by *always* using raw strings for TeX. The reason your "bad" cases are bad is that \b and \t are escape sequences; in an ordinary string, without the leading r, the two-character sequences are translated into control characters (bell and tab, respectively). \i is not an escape sequence, so it gets left alone.
etc but it not working (like I expected). So I would like to know if there are
a way to precise that the text is a raw string by another thing that the r
character just before the string. Perhaps that will be good to have an option
like raw=true or something similar?
Thanks,
N.
···
Le Mardi 31 Octobre 2006 23:14, Eric Firing a écrit :
humufr@...136... wrote:
> Hi,
>
> I have different questions to use tex with matplotlib.
>
> The first one:
>
> If I'm doing:
>
> rc('text', usetex=True)
> xlabel('\\textrm\{toto\}') # bad
> xlabel(r'\\textrm\{toto\}') # ok
>
> The results are not the same and I don't understand why.
>
> and for:
>
> xlabel('\\textit\{toto\}') #bad
> xlabel(r'\\textit\{toto\}') #ok
>
> same things, but it's working fine for:
>
> xlabel('\\it\{toto\}') #ok
> xlabel(r'\\it\{toto\}') #ok
>
> but it's not working for \bf:
>
> xlabel('\\textbf\{toto\}') # bad
> xlabel(r'\\textbf\{toto\}') # ok
> xlabel('\\bf\{toto\}') # bad
> xlabel(r'\\bf\{toto\}') # ok
>
> And this bring to the second question, I would like to create the xlabel
> with latex stuf inside somewhere in my script:
>
> label='\\textrm\{test\}\_2'
>
> but that can't work:
>
> xlabel(label) # bad
>
> How to tell that I want the "r" before the chains to have TeX working
> like expected?
I think you have much to gain and nothing to lose by *always* using raw
strings for TeX. The reason your "bad" cases are bad is that \b and \t
are escape sequences; in an ordinary string, without the leading r, the
two-character sequences are translated into control characters (bell and
tab, respectively). \i is not an escape sequence, so it gets left alone.
etc but it not working (like I expected). So I would like to know if there are a way to precise that the text is a raw string by another thing that the r character just before the string. Perhaps that will be good to have an option like raw=true or something similar?
There is no such thing as a raw string *object*. There are only raw string *literals*. The r'' determines how the source code is parsed, not how the contents of the object is treated.
label = r'\\textrm\{test\}\_2'
xlabel(label)
After the source code containing the string literal is parsed, the string is simply a string.
···
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
Thank you very much I didn't know this. That will be very helpful.
N.
···
Le Mardi 31 Octobre 2006 23:47, Robert Kern a écrit :
humufr@...136... wrote:
> I tried:
>
> label='\\textrm\{test\}\_2
> xlabel(r label)
> xlabel(r+label)
>
> etc but it not working (like I expected). So I would like to know if
> there are a way to precise that the text is a raw string by another thing
> that the r character just before the string. Perhaps that will be good to
> have an option like raw=true or something similar?
There is no such thing as a raw string *object*. There are only raw string
*literals*. The r'' determines how the source code is parsed, not how the
contents of the object is treated.
label = r'\\textrm\{test\}\_2'
xlabel(label)
After the source code containing the string literal is parsed, the string
is simply a string.