Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ValueError: unsupported format character '

Tags:

python

I got most of the following code from here: Generating pdf-latex with python script

#!/usr/bin/env python

from __future__ import division
from functions import *
import shlex

#from Utilities import *
import os
import argparse
import subprocess

equation = '\begin{equation*}1 + \gamma\lambda B/2\end{equation*}'

content=r'''\documentclass{article}
\usepackage{graphicx,amsmath}

\begin{document}
\noindent\rotatebox{180}{\vbox{%
    %(equation)s
    }%
}
\end{document}
'''

parser=argparse.ArgumentParser()
parser.add_argument('-e', '--equation', default=equation)

args=parser.parse_args()
content%args.__dict__

print content%args.__dict__

running this code gives me the following error:

Traceback (most recent call last):
  File "latex.py", line 29, in <module>
    content%args.__dict__
ValueError: unsupported format character '
' (0xa) at index 104

anybody know what's going wrong? I've got the same error from other methods of rotating the page.

like image 469
juggler Avatar asked Dec 09 '13 20:12

juggler


1 Answers

Any % in content is seen as a formatting placeholder. Double any that are not a placeholder:

content=r'''\documentclass{article}
\usepackage{graphicx,amsmath}

\begin{document}
\noindent\rotatebox{180}{\vbox{%%
    %(equation)s
    }%%
}
\end{document}
'''

Otherwise the % at the end of the \noindent\rotatebox{180}{\vbox{% line is seen together with the \n newline as a formatting character, hence the exception with an embedded newline.

like image 118
Martijn Pieters Avatar answered Sep 21 '22 04:09

Martijn Pieters