- changed milestone to 1.4
ufl to latex support broken in several ways
Consider the following script, which attempts to make a PDF file from the UFL representation of a functional.
from dolfin import *
mesh = UnitSquareMesh(100, 100)
V = VectorFunctionSpace(mesh, "CG", 1) + VectorFunctionSpace(mesh, "Bubble", 3)
P = FunctionSpace(mesh, "CG", 1)
C = FunctionSpace(mesh, "CG", 1)
R = FunctionSpace(mesh, "R", 0)
Z = MixedFunctionSpace([V, P, C, R, R]) # One to ensure that p*dx == 0, the other is the Lagrange multiplier to ensure rho*dx == input
mu = Constant(1.0e-3)
q = Constant(0.1)
alphabar = Constant(2.5e4)
gamma = Constant(0.5)
def alpha(rho):
return alphabar * q * ((q + 1)/(rho + q) - 1)
z = Function(Z)
(u, p, rho, p0, lmbda) = split(z)
J = ( 0.5 * inner(grad(u), grad(u))*dx
- inner(p, div(u))*dx
- inner(p0, p)*dx )
if rho is not None:
J = J + 0.5 * alpha(rho) * inner(u, u)*dx
J = ( J
- mu * ln(rho*(1 - rho))*dx
+ inner(lmbda, rho - gamma)*dx)
from ufl.algorithms.ufl2latex import *
forms = [J]
latex = forms2latexdocument(forms, 'dummy.ufl', compile=False)
write_file('J.tex', latex)
pdflatex('J.tex', 'J.pdf', flags=None)
A few issues.
(a) I had to change
form = preprocess(form)
form_data = form.form_data()
to
form_data = preprocess(form)
in ufl/algorithms/ufl2latex.py; it appears that the output of preprocess has changed to become the desired form data, rather than a form with the form data attached.
(b) tex2pdf calls pdflatex(latexfilename, pdffilename)
but that gives an error now:
TypeError: pdflatex() takes exactly 3 arguments (2 given)
Looking at the definition of pdflatex,
def pdflatex(latexfilename, pdffilename, flags): # TODO: Options for this.
"Execute pdflatex to compile a latex file into pdf."
flags = "-file-line-error-style -interaction=nonstopmode"
It takes in a third argument and immediately ignores it.
(c)
The compilation of the .tex failed --- in the .log, it gives lots of errors like
./J.tex:17: Missing $ inserted.
<inserted text>⋅
$
l.17 \end{align}
⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅
I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.
./J.tex:17: Extra }, or forgotten $.
Comments (5)
-
-
- changed milestone to 1.5
-
The immediate bug is fixed. The latex output must be manually edited to be usable but I don't intend to fix that any time soon, so closing.
-
- changed status to resolved
-
- removed milestone
Removing milestone: 1.5 (automated comment)
- Log in to comment