Escape LaTex special characters.

This commit is contained in:
Tim Schumacher 2013-08-14 20:51:35 +02:00
parent b414752231
commit 2cbdccd9de

View file

@ -33,6 +33,18 @@ function EventTool() {
events.EventEmitter.call(this); events.EventEmitter.call(this);
}; };
String.prototype.EscapeLatex = function() {
return this.toString()
.replace(/&/g,'&')
.replace(/\\/g,'\\textbackslash{}')
.replace(/&/g,'\\&')
.replace(/\|/g,'\\|')
.replace(/\[/g,'\\[')
.replace(/\]/g,'\\]')
.replace(/\%/g,'\\%')
.replace(/\$/g,'\\$');
}
EventTool.super_ = events.EventEmitter; EventTool.super_ = events.EventEmitter;
EventTool.prototype = Object.create(events.EventEmitter.prototype, { EventTool.prototype = Object.create(events.EventEmitter.prototype, {
constructor: { constructor: {
@ -95,6 +107,10 @@ EventTool.prototype.publishLatex = function() {
var self = this; var self = this;
log('Erzeuge PDFs mit LaTeX'); log('Erzeuge PDFs mit LaTeX');
var view = self.processEventData(); var view = self.processEventData();
view.events.forEach(function(el){
el.heading = el.heading.EscapeLatex();
el.text = el.text.EscapeLatex();
});
// generate the pdfs // generate the pdfs
self.config.latex.templates.forEach(function(template){ self.config.latex.templates.forEach(function(template){
var templateData = fs.readFileSync('templates/latex/'+template+'.tex','utf-8'); var templateData = fs.readFileSync('templates/latex/'+template+'.tex','utf-8');