-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Issue #1888: added in the \dfrac macro for displaystyle fractions #8151
New issue
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
Changes from 2 commits
4b9ff60
45f5d63
bedfdc0
0d10078
2c9b9bc
57fd910
d0cfe37
7781dbd
b80d975
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env python2 | ||
# -*- coding: utf-8 -*- | ||
""" | ||
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. This needs to be a raw string or all the backslashes need to be escaped (which probably won't look that great.) |
||
Created on Sat Feb 25 17:50:37 2017 | ||
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. Remove this date; we have |
||
|
||
@author: watkinrt | ||
""" | ||
|
||
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') | ||
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. Needs 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. Man, you guys are fast and thorough. I'm working on all of the requested changes. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2309,6 +2309,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() | ||
|
@@ -2397,6 +2398,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}")) | ||
|
@@ -2449,6 +2455,7 @@ def __init__(self): | |
| p.function | ||
| p.group | ||
| p.frac | ||
| p.dfrac | ||
| p.stackrel | ||
| p.binom | ||
| p.genfrac | ||
|
@@ -3043,8 +3050,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 | ||
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. I think these warrant some constants instead of magic numbers. |
||
if style: | ||
num.shrink() | ||
den.shrink() | ||
cnum = HCentered([num]) | ||
cden = HCentered([den]) | ||
width = max(num.width, den.width) | ||
|
@@ -3077,35 +3087,46 @@ 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) | ||
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. 👍 for the whitespace fix, but also, you don't really need the parentheses. |
||
|
||
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, 1, 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, 0, 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, 1, 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, 1, num, den) | ||
|
||
def sqrt(self, s, loc, toks): | ||
#~ print "sqrt", toks | ||
|
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.
remove the pinning to python2
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.
Will do. This is my first contribution, so I'm still working out some of the bugs. Thanks for the prompt suggestions.