def formula(quantity): """ returns error formula of quantity as latex code Args: quantity: Quantity object Return: latex code string of error formula """ assert isinstance(quantity, Quantity) if quantity.error_formula is None: raise ValueError("quantity '%s' doesn't have an error formula." % quantity.name) formula = quantity.error_formula if isinstance(formula,str): return formula else: # replace "_err" by sigma function sigma = Function("\sigma") for var in formula.free_symbols: if var.name[-4:] == "_err": formula = formula.subs(var, sigma( Symbol(var.name[:-4], **var._assumptions))) latex_code = latex(sigma(quantity)) + " = " + latex(formula) form_button, form_code = pytex.hide_div('Formula', '$%s$' % (latex_code) , hide = False) latex_button, latex_code = pytex.hide_div('LaTex', latex_code) res = 'Error Formula for %s<div width=20px/>%s%s<hr/>%s<br>%s' % ( '$%s$' % latex(quantity), form_button, latex_button, form_code, latex_code) return render_latex(res)
def table(self, *quants, maxcols=5, latexonly=False): quants = [self[quant] for quant in quants] if latexonly: return quantities.qtable(*quants, html=False, maxcols=maxcols)[0] else: return render_latex(quantities.qtable(*quants, maxcols=maxcols))