ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 21 Mar 2018 14:27:07 +0100quick latex questionhttps://ask.sagemath.org/question/41644/quick-latex-question/ I am writing a worksheet for an ODE course and would like to display the following equation as $$y''+y=1$$ OR as $$\frac{d^2y}{dx^2}+y=1$$ However sage always reverts to partials. Is there an easy way to display these as ordinary differential equations?
thx
see sage cell [link text](https://sagecell.sagemath.org/?z=eJyrUFBQsFUoSyzSUK9Q17Tm5aoEC6SV5iWXZObnaahXqmtqVIAkXFwDgRIpmWlpGpU6FZoK2gqVCroKhra2BkDJ4vwckGQqkC5L1QAq1VGoBGkCymTkl4MENHm5Cooy80o0chJLUivAIpoAAaUhcw==&lang=sage)Mon, 19 Mar 2018 19:25:22 +0100https://ask.sagemath.org/question/41644/quick-latex-question/Answer by slelievre for <p>I am writing a worksheet for an ODE course and would like to display the following equation as $$y''+y=1$$ OR as $$\frac{d^2y}{dx^2}+y=1$$ However sage always reverts to partials. Is there an easy way to display these as ordinary differential equations?</p>
<p>thx</p>
<p>see sage cell <a href="https://sagecell.sagemath.org/?z=eJyrUFBQsFUoSyzSUK9Q17Tm5aoEC6SV5iWXZObnaahXqmtqVIAkXFwDgRIpmWlpGpU6FZoK2gqVCroKhra2BkDJ4vwckGQqkC5L1QAq1VGoBGkCymTkl4MENHm5Cooy80o0chJLUivAIpoAAaUhcw==&lang=sage">link text</a></p>
https://ask.sagemath.org/question/41644/quick-latex-question/?answer=41679#post-id-41679Possibly a duplicate of
- [https://ask.sagemath.org/question/7826/latex-typesetting-for-derivatives-like-g/](https://ask.sagemath.org/question/7826/latex-typesetting-for-derivatives-like-g/)
A quick and dirty workaround would be to replace your original code:
x = var('x')
y = function('y')(x)
DEQ = diff(y,x) + y - 1 == 0
sol = desolve(DEQ, y)
show(DEQ)
print(latex(DEQ))
by something along the lines of:
sage: x = SR.var('x')
sage: y = function('y')(x)
sage: de = diff(y, x) + y - 1 == 0
sage: de
y(x) + diff(y(x), x) - 1 == 0
sage: y1 = function("y'")(x)
sage: de_pretty = de.substitute({diff(y, x): y1})
sage: de_pretty
y(x) + y'(x) - 1 == 0
and running `show` or `view` or `latex` on `de_pretty` rather than `de`.
One could write a function to prettify differential equations,
by parsing the expression tree of the differential equation,
and substituting derivatives by aptly named replacement functions.
One would then run `desolve` on the original differential equation,
and use the prettified equation for showing, viewing, latexing.
Or maybe it would be easier to work the other way! Start by defining
the pretty differential equation, and substitute an actual differential
equation for solving.Wed, 21 Mar 2018 14:27:07 +0100https://ask.sagemath.org/question/41644/quick-latex-question/?answer=41679#post-id-41679