Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d9ee67d

Browse files
committed
added accents to mathtext
svn path=/trunk/matplotlib/; revision=875
1 parent 557459e commit d9ee67d

3 files changed

Lines changed: 45 additions & 14 deletions

File tree

CHANGELOG

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ New entries should be added at the top
33
2005-01-18 Added accents to mathtext: \hat, \breve, \grave, \bar,
44
\acute, \tilde, \vec, \dot, \ddot. All of them have the same
55
syntax, eg to make an overbar you do \bar{o} or to make an o umlaut
6-
you do \ddot{o} - JDH
6+
you do \ddot{o}. The shortcuts are also provided, eg: \"o \'e \`e
7+
\~n \.x \^y - JDH
78

8-
2005-01-18 Plugged an image resize memory leaks - JDH
9+
2005-01-18 Plugged image resize memory leaks - JDH
910

1011
2005-01-18 Fixed some mathtext parser problems relating to superscripts
1112

examples/accented_text.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
matplotlib supports accented characters via TeX mathtext
3+
4+
The following accents are provided: \hat, \breve, \grave, \bar,
5+
\acute, \tilde, \vec, \dot, \ddot. All of them have the same syntax,
6+
eg to make an overbar you do \bar{o} or to make an o umlaut you do
7+
\ddot{o}. The shortcuts are also provided, eg: \"o \'e \`e \~n \.x
8+
\^y
9+
10+
"""
11+
from pylab import *
12+
13+
plot(range(10))
14+
15+
title(r'$\ddot{o}\acute{e}\grave{e}\hat{O}\breve{i}\bar{A}\tilde{n}\vec{q}$', fontsize=20)
16+
# shorthad is also supported
17+
xlabel(r"""$\"o\'e\`e\~n\.x\^y$""", fontsize=20)
18+
19+
20+
show()

lib/matplotlib/mathtext.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
The following accents are provided: \hat, \breve, \grave, \bar,
2222
\acute, \tilde, \vec, \dot, \ddot. All of them have the same
2323
syntax, eg to make an overbar you do \bar{o} or to make an o umlaut
24-
you do \ddot{o}.
24+
you do \ddot{o}. The shortcuts are also provided, eg: \"o \'e \`e
25+
\~n \.x \^y
2526
2627
The spacing elements \ , \/ and \hspace{num} are provided. \/
2728
inserts a small space, and \hspace{num} inserts a fraction of the
@@ -795,15 +796,21 @@ def accent(self, s, loc, toks):
795796
accent, sym = toks[0]
796797

797798
d = {
798-
r'\hat' : r'\circumflexaccent',
799-
r'\breve' : r'\combiningbreve',
800-
r'\bar' : r'\combiningoverline',
801-
r'\grave' : r'\combininggraveaccent',
802-
r'\acute' : r'\combiningacuteaccent',
803-
r'\ddot' : r'\combiningdiaeresis',
804-
r'\tilde' : r'\combiningtilde',
805-
r'\dot' : r'\combiningdotabove',
806-
r'\vec' : r'\combiningrightarrowabove',
799+
r'\hat' : r'\circumflexaccent',
800+
r'\breve' : r'\combiningbreve',
801+
r'\bar' : r'\combiningoverline',
802+
r'\grave' : r'\combininggraveaccent',
803+
r'\acute' : r'\combiningacuteaccent',
804+
r'\ddot' : r'\combiningdiaeresis',
805+
r'\tilde' : r'\combiningtilde',
806+
r'\dot' : r'\combiningdotabove',
807+
r'\vec' : r'\combiningrightarrowabove',
808+
r'\"' : r'\combiningdiaeresis',
809+
r"\`" : r'\combininggraveaccent',
810+
r"\'" : r'\combiningacuteaccent',
811+
r'\~' : r'\combiningtilde',
812+
r'\.' : r'\combiningdotabove',
813+
r'\^' : r'\circumflexaccent',
807814
}
808815
above = SymbolElement(d[accent])
809816
sym.neighbors['above'] = above
@@ -913,7 +920,10 @@ def subsuperscript(self, s, loc, toks):
913920

914921
accent = Literal('hat') | Literal('check') | Literal('dot') | \
915922
Literal('breve') | Literal('acute') | Literal('ddot') | \
916-
Literal('grave') | Literal('tilde') | Literal('bar') | Literal('vec')
923+
Literal('grave') | Literal('tilde') | Literal('bar') | \
924+
Literal('vec') | Literal('"') | Literal("`") | Literal("'") |\
925+
Literal('~') | Literal('.') | Literal('^')
926+
917927

918928

919929

@@ -953,7 +963,7 @@ def subsuperscript(self, s, loc, toks):
953963
#~ composite = Group( Combine(bslash + composite) + group + group).setParseAction(handler.composite).setName("composite")
954964
composite = Group( Combine(bslash + overUnder) + group + group).setParseAction(handler.composite).setName("composite")
955965

956-
accent = Group( Combine(bslash + accent) + group).setParseAction(handler.accent).setName("accent")
966+
accent = Group( Combine(bslash + accent) + Optional(lbrace) + symbol + Optional(rbrace)).setParseAction(handler.accent).setName("accent")
957967

958968
#~ symgroup = symbol ^ group
959969
symgroup = symbol | group

0 commit comments

Comments
 (0)