| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| r""" | ||
| ========================================= | ||
| The difference between \\dfrac and \\frac | ||
| ========================================= | ||
|
|
||
| In this example, the differences between the \\dfrac and \\frac TeX macros are | ||
| illustrated; in particular, the difference between display style and text style | ||
| fractions when using Mathtex. | ||
|
|
||
| .. versionadded:: 2.1 | ||
|
|
||
| .. note:: | ||
| To use \\dfrac with the LaTeX engine (text.usetex : True), you need to | ||
| import the amsmath package with the text.latex.preamble rc, which is | ||
| an unsupported feature; therefore, it is probably a better idea to just | ||
| use the \\displaystyle option before the \\frac macro to get this behavior | ||
| with the LaTeX engine. | ||
|
|
||
| """ | ||
|
|
||
| import matplotlib.pyplot as plt | ||
|
|
||
| fig = plt.figure(figsize=(5.25, 0.75)) | ||
| fig.text(0.5, 0.3, r'\dfrac: $\dfrac{a}{b}$', | ||
| horizontalalignment='center', verticalalignment='center') | ||
| fig.text(0.5, 0.7, r'\frac: $\frac{a}{b}$', | ||
| horizontalalignment='center', verticalalignment='center') | ||
| plt.show() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -2216,6 +2216,10 @@ class Parser(object): | |
| The grammar is based directly on that in TeX, though it cuts a few | ||
| corners. | ||
| """ | ||
|
|
||
| _math_style_dict = dict(displaystyle=0, textstyle=1, | ||
| scriptstyle=2, scriptscriptstyle=3) | ||
|
|
||
| _binary_operators = set(''' | ||
| + * - | ||
| \\pm \\sqcap \\rhd | ||
| Expand Down Expand Up | @@ -2301,6 +2305,7 @@ def __init__(self): | |
| p.float_literal = Forward() | ||
| p.font = Forward() | ||
| p.frac = Forward() | ||
| p.dfrac = Forward() | ||
| p.function = Forward() | ||
| p.genfrac = Forward() | ||
| p.group = Forward() | ||
| Expand Down Expand Up | @@ -2389,6 +2394,11 @@ def __init__(self): | |
| - ((p.required_group + p.required_group) | Error(r"Expected \frac{num}{den}")) | ||
| ) | ||
|
|
||
| p.dfrac <<= Group( | ||
| Suppress(Literal(r"\dfrac")) | ||
| - ((p.required_group + p.required_group) | Error(r"Expected \dfrac{num}{den}")) | ||
| ) | ||
|
|
||
| p.stackrel <<= Group( | ||
| Suppress(Literal(r"\stackrel")) | ||
| - ((p.required_group + p.required_group) | Error(r"Expected \stackrel{num}{den}")) | ||
| Expand Down Expand Up | @@ -2441,6 +2451,7 @@ def __init__(self): | |
| | p.function | ||
| | p.group | ||
| | p.frac | ||
| | p.dfrac | ||
| | p.stackrel | ||
| | p.binom | ||
| | p.genfrac | ||
| Expand Down Expand Up | @@ -3035,8 +3046,11 @@ def _genfrac(self, ldelim, rdelim, rule, style, num, den): | |
| state.font, state.fontsize, state.dpi) | ||
|
|
||
| rule = float(rule) | ||
| num.shrink() | ||
| den.shrink() | ||
|
|
||
| # If style != displaystyle == 0, shrink the num and den | ||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI think these warrant some constants instead of magic numbers.
Sorry, something went wrong.
All reactions
|
||
| if style != self._math_style_dict['displaystyle']: | ||
| num.shrink() | ||
| den.shrink() | ||
| cnum = HCentered([num]) | ||
| cden = HCentered([den]) | ||
| width = max(num.width, den.width) | ||
| Expand Down Expand Up | @@ -3069,35 +3083,50 @@ def _genfrac(self, ldelim, rdelim, rule, style, num, den): | |
| return result | ||
|
|
||
| def genfrac(self, s, loc, toks): | ||
| assert(len(toks)==1) | ||
| assert(len(toks[0])==6) | ||
| assert(len(toks) == 1) | ||
| assert(len(toks[0]) == 6) | ||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality👍 for the whitespace fix, but also, you don't really need the parentheses.
Sorry, something went wrong.
All reactions
|
||
|
|
||
| return self._genfrac(*tuple(toks[0])) | ||
|
|
||
| def frac(self, s, loc, toks): | ||
| assert(len(toks)==1) | ||
| assert(len(toks[0])==2) | ||
| assert(len(toks) == 1) | ||
| assert(len(toks[0]) == 2) | ||
| state = self.get_state() | ||
|
|
||
| thickness = state.font_output.get_underline_thickness( | ||
| state.font, state.fontsize, state.dpi) | ||
| num, den = toks[0] | ||
|
|
||
| return self._genfrac('', '', thickness, | ||
| self._math_style_dict['textstyle'], num, den) | ||
|
|
||
| def dfrac(self, s, loc, toks): | ||
| assert(len(toks) == 1) | ||
| assert(len(toks[0]) == 2) | ||
| state = self.get_state() | ||
|
|
||
| thickness = state.font_output.get_underline_thickness( | ||
| state.font, state.fontsize, state.dpi) | ||
| num, den = toks[0] | ||
|
|
||
| return self._genfrac('', '', thickness, '', num, den) | ||
| return self._genfrac('', '', thickness, | ||
| self._math_style_dict['displaystyle'], num, den) | ||
|
|
||
| def stackrel(self, s, loc, toks): | ||
| assert(len(toks)==1) | ||
| assert(len(toks[0])==2) | ||
| assert(len(toks) == 1) | ||
| assert(len(toks[0]) == 2) | ||
| num, den = toks[0] | ||
|
|
||
| return self._genfrac('', '', 0.0, '', num, den) | ||
| return self._genfrac('', '', 0.0, | ||
| self._math_style_dict['textstyle'], num, den) | ||
|
|
||
| def binom(self, s, loc, toks): | ||
| assert(len(toks)==1) | ||
| assert(len(toks[0])==2) | ||
| assert(len(toks) == 1) | ||
| assert(len(toks[0]) == 2) | ||
| num, den = toks[0] | ||
|
|
||
| return self._genfrac('(', ')', 0.0, '', num, den) | ||
| return self._genfrac('(', ')', 0.0, | ||
| self._math_style_dict['textstyle'], num, den) | ||
|
|
||
| def sqrt(self, s, loc, toks): | ||
| #~ print "sqrt", toks | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityNeeds plt.show at the end.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityMan, you guys are fast and thorough. I'm working on all of the requested changes.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.