Sorry if this is a repost; I'm sure this question gets asked often but I couldn't find exactly what I was after in the search. I'm trying to write a scientific plotting program in matplotlib (using python 2.7) and I'm having trouble getting it to recognise LaTeX code the way I expect.

On the matplotlib site, there is an example which works perfectly on my machine (Ubuntu 12.04):

But when I try and apply the concepts from this to my existing code, things go awry. My code is reading in values from a text file to use as strings for the titles and axes for a series of subplots. the text file looks like this only one line break per line in the original:

Example \texit{plot title}

x label

y label

So I'm expecting everything to be ordinary except "plot title", which should be italic. Here is the function that I have written:

Where "formatting_file" is a string (path to the file with the above contents), and everything works as expected without the Tex formatting attempt (if I remove the lines starting with rc). When I run this, however, I get a wall of tracebacks ending with:

It boils down to this: I don't have a lot of experience with LaTeX, but I'm trying to learn, so I don't understand these errors. I don't understand why my code doesn't work when it doesn't seem to be an awful lot different from the example which does. For reference, I have also tried this on an x86 Windows 7 machine with the same result.

What am I missing?

EDIT:

I suppose the code snippet I supplied for my example is excessively long. A shorter, simpler version would be along these lines:

Questions on TeX - LaTeX Stack Exchange are expected to relate to TeX, LaTeX or related typesetting systems within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.
If this question can be reworded to fit the rules in the help center, please edit the question.

1

Welcome to TeX.sx! It would be very useful to have a complete Minimal Working Example (MEW) of LaTeX code that generates the error so that people can reproduce it and possibly find solutions.
–
Peter JanssonJan 17 '13 at 11:21

Hi Peter, thanks for the welcome. I've edited the question and added a shorter code snippet which should work independently to show what I'm trying to do. Do you think this would have been better posted to a different stackexchange (i.e. one dealing more with programming in python)?
–
Magic_Matt_ManJan 17 '13 at 11:30

I can't test your code but I assume \texit which you have in several places is a typo for \textit which would make italic text and is used in the first template that you show.
–
David CarlisleJan 17 '13 at 12:02

Thanks for pointing that out. I've made the change but still get the RunTimeError.
–
Magic_Matt_ManJan 17 '13 at 12:18

Thank you for your answer. I did have rstrip in there at one point before, but obviously my implementation of it was flawed. I copied your suggestion in and it no longer throws the exception- the text still doesn't quite render as I expected, but at least it renders. One final note: sorry for posting this in the wrong stackexchange; I knew I was pushing my luck a little but I thought it was still close enough to TeX topics. I'll try and avoid that in future.
–
Magic_Matt_ManJan 18 '13 at 10:21