Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

parentheses in latex are off by default. added latex information to t…

  • Loading branch information...
commit 9baf3bc3f1a565afad5829e1fdd33c407651c844 1 parent f9c43c2
@robfalck authored
Showing with 24 additions and 3 deletions.
  1. +21 −0 quantities/
  2. +3 −3 quantities/
21 quantities/
@@ -213,6 +213,27 @@
>>> print pq.constants.proton_mass.simplified
1.672621637e-27 kg
+/-8.3e-35 kg (1 sigma)
+A Latex representation of the dimensionality may be obtained in the following fashion::
+ >>> g = pq.Quantity(9.80665,'m/s**2')
+ >>> mass = 50 *
+ >>> weight = mass*g
+ >>> print weight.dimensionality.latex
+ $\mathrm{\frac{kg{\cdot}m}{s^{2}}}$
+ >>> weight.units = pq.N
+ >>> print weight.dimensionality.latex
+ $\mathrm{N}$
+The Latex output is compliant with the MathText subset used by Matplotlib. To add
+formatted units to the axis label of a Matplotlib figure, one could use::
+ >>> ax.set_ylabel('Weight ' + weight.dimensionality.latex)
+Greater customization is available via the markup.format_units_latex function. It allows
+the user to modify the font, the multiplication symbol, or to encapsulate the latex
+string in parentheses. Due to the complexity of CompoundUnits, the latex rendering
+of CompoundUnits will utilize the latex \frac{num}{den} construct.
Although it is not illustrated in this guide, unicode symbols can be
used to provide a more compact representation of the units. This
6 quantities/
@@ -87,7 +87,7 @@ def format_units_unicode(udict):
return res
-def format_units_latex(udict,font='mathrm',mult=r'\cdot',paren=True):
+def format_units_latex(udict,font='mathrm',mult=r'\cdot',paren=False):
Replace the units string provided with an equivalent latex string.
@@ -100,8 +100,8 @@ def format_units_latex(udict,font='mathrm',mult=r'\cdot',paren=True):
'mathit', 'mathsf', and 'mathtt'.
Multiplication (*) are replaced with the symbol specified by the mult argument.
- By default this is a blank string (no multiplication symbol). Other useful
- options may be r'\cdot' or r'*'
+ By default this is the latex \cdot symbol. Other useful
+ options may be '' or '*'.
If paren=True, encapsulate the string in '\left(' and '\right)'
Please sign in to comment.
Something went wrong with that request. Please try again.