I use python3 (with code not from me) to insert data from a database (bsddb3) from the program GRAMPS into a LaTeX document (TeX Live 2014) and I receive the following error messages:
! Missing $ inserted.
<inserted text>
$
l.1131 ...{Foto_Kurt_Neumann"=1 Kurt Neumann 1915}
%
! ==> Fatal error occurred, no output PDF file produced!
The relevant part of the python code is:
self.media_added.add(media_ref.ref)
path = media_path_full(self.database, media.get_path())
desc = media.get_description()
text = ""
notelist = media.get_note_list()
for notehandle in notelist:
note = self.database.get_note_from_handle(notehandle)
text += le(note.get())
if intern:
text += "{\\small\\textit{Bild-ID: %s}}" % (media.get_gramps_id())
draft_opt = ""
if draft:
draft_opt = "draft,"
tcstar = ''
if twocolumn:
tcstar = '*'
file.write('''%%
\\begin{figure%s}[tb!p]
\\raggedright%%
\\setlength\\fboxrule{.25pt}
\\setlength\\fboxsep{.25pt}
\\color{rulecolor}
\\fbox{%%
\\setlength{\\imgwidth}{\\linewidth}%%
\\addtolength{\\imgwidth}{-1pt}%%
\\includegraphics[%swidth=\\imgwidth,height=1.5\\imgwidth,keepaspectratio]{%s}%%
}%%
\\color{textcolor}%%
\\caption[%s]{%s %s}%%
\\label{fig:%s}%%
\\end{figure%s}%%
''' % (tcstar, draft_opt, path, le(desc), le(desc), text, media.get_handle(), tcstar))
I have hours trying to solve it now, I do not see where the problem is!?
I tried to add the math mode in \caption
:
\\caption[%s]{$%s %s$}%%
But run into an even more crypted (related?) issue, I do not know where it comes from.
Runaway argument?
! Paragraph ended before " was complete.
<to be read again>
\par
I am totally lost with this error.
Edit
# Latex-Encode
def le(str):
str = re.sub(r'"\b', r'"', str)
str = re.sub(r'\b"', r'"', str)
str = re.sub(r' km\b', r'\\,km', str)
str = re.sub(r'[\.,!\?]"', r'"', str)
str = re.sub(r'"', r'"', str)
str = str.replace("_", "\_")
str = re.sub(r'(\[[0-9a-e ]+\])', r'\\numberreference{\1}', str)
str = re.sub(r'(http://[\w\d/\._?&=-]+)',r'\\url{\1}', str)
str = str.replace('−','--')
str = str.replace('&','\\&')
str = str.replace("<u>",'\\rufname{')
str = str.replace("</u>","}")
str = str.replace("-)","\"~)")
str = str.replace("S. ","S.~")
str = re.sub(r'\)([a-zA-Z])',r')""\1',str)
str = str.replace("-/","\"~/")
str = str.replace("-","\"=")
str = str.replace("/","\\slash{}")
str = re.sub(r'\\url{([^}]*)"=',r'\\url{\1-',str)
str = re.sub(r'\\url{([^}]*)\\slash{}',r'\\url{\1/',str)
str = re.sub(r'\\url{([^}]*)"=',r'\\url{\1-',str)
str = re.sub(r'\\url{([^}]*)\\slash{}',r'\\url{\1/',str)
str = re.sub(r'\\url{([^}]*)"=',r'\\url{\1-',str)
str = re.sub(r'\\url{([^}]*)\\slash{}',r'\\url{\1/',str)
str = re.sub(r'\\url{([^}]*)"=',r'\\url{\1-',str)
str = re.sub(r'\\url{([^}]*)\\slash{}',r'\\url{\1/',str)
str = re.sub(r'\\url{([^}]*)"=',r'\\url{\1-',str)
str = re.sub(r'\\url{([^}]*)\\slash{}',r'\\url{\1/',str)
str = re.sub(r'\\url{([^}]*)"=',r'\\url{\1-',str)
str = re.sub(r'\\url{([^}]*)\\slash{}',r'\\url{\1/',str)
str = str.replace("#10^00#",'10\\textsuperscript{00}')
str = str.replace(" #LEBENSLAUF#",'~\\pageref{lebenslauf}')
return str
str2 = ''
for c in str:
if ord(c)>127:
str2 += '\mbox{%s}'%c
else:
str2 += c
return str2
_
becomes\_
. Simply typesetting the caption in math mode won't get you satisfying results. – Johannes_B May 11 '15 at 14:10str = str.replace("_", "\_")
in the python code, than I get the same runaway argument. I have a bunch of latex ecoding already, see edit. – Til Hund May 11 '15 at 14:31