LaTeX export now supports escaping, with a warning if it fails
This commit is contained in:
@@ -24,6 +24,7 @@ class LaTeXFile(TextFile):
|
|||||||
def __init__(self, theProject, theParent):
|
def __init__(self, theProject, theParent):
|
||||||
TextFile.__init__(self, theProject, theParent)
|
TextFile.__init__(self, theProject, theParent)
|
||||||
self.theConv = ToLaTeX(self.theProject, self.theParent)
|
self.theConv = ToLaTeX(self.theProject, self.theParent)
|
||||||
|
self.texCodecFail = False
|
||||||
return
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
@@ -50,6 +51,8 @@ class LaTeXFile(TextFile):
|
|||||||
self.outFile.write("\\end{document}\n")
|
self.outFile.write("\\end{document}\n")
|
||||||
self.outFile.close()
|
self.outFile.close()
|
||||||
|
|
||||||
|
self.texCodecFail = self.theConv.texCodecFail
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# END Class LaTeXFile
|
# END Class LaTeXFile
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import textwrap
|
|
||||||
import logging
|
import logging
|
||||||
import codecs
|
import codecs
|
||||||
import re
|
import re
|
||||||
@@ -38,34 +37,6 @@ class ToLaTeX(Tokenizer):
|
|||||||
self.FMT_U_E : r"}",
|
self.FMT_U_E : r"}",
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.wordWrap > 0:
|
|
||||||
tWrap = textwrap.TextWrapper(
|
|
||||||
width = self.wordWrap,
|
|
||||||
initial_indent = "",
|
|
||||||
subsequent_indent = "",
|
|
||||||
expand_tabs = True,
|
|
||||||
replace_whitespace = True,
|
|
||||||
fix_sentence_endings = False,
|
|
||||||
break_long_words = True,
|
|
||||||
drop_whitespace = True,
|
|
||||||
break_on_hyphens = True,
|
|
||||||
tabsize = 8,
|
|
||||||
max_lines = None
|
|
||||||
)
|
|
||||||
tComm = textwrap.TextWrapper(
|
|
||||||
width = self.wordWrap-2,
|
|
||||||
initial_indent = "",
|
|
||||||
subsequent_indent = "",
|
|
||||||
expand_tabs = True,
|
|
||||||
replace_whitespace = True,
|
|
||||||
fix_sentence_endings = False,
|
|
||||||
break_long_words = True,
|
|
||||||
drop_whitespace = True,
|
|
||||||
break_on_hyphens = True,
|
|
||||||
tabsize = 8,
|
|
||||||
max_lines = None
|
|
||||||
)
|
|
||||||
|
|
||||||
self.theResult = ""
|
self.theResult = ""
|
||||||
thisPar = []
|
thisPar = []
|
||||||
for tType, tText, tFormat, tAlign in self.theTokens:
|
for tType, tText, tFormat, tAlign in self.theTokens:
|
||||||
@@ -89,14 +60,6 @@ class ToLaTeX(Tokenizer):
|
|||||||
|
|
||||||
tLen = len(tText)
|
tLen = len(tText)
|
||||||
|
|
||||||
# The text can now be word wrapped, if we have requested this and it's needed.
|
|
||||||
if self.wordWrap > 0 and tLen > self.wordWrap:
|
|
||||||
if tType == self.T_COMMENT:
|
|
||||||
aText = tComm.wrap(tText)
|
|
||||||
tText = "\n% ".join(aText)
|
|
||||||
else:
|
|
||||||
tText = tWrap.fill(tText)
|
|
||||||
|
|
||||||
# Then the text can receive final formatting before we append it to the results.
|
# Then the text can receive final formatting before we append it to the results.
|
||||||
# We also store text lines in a buffer and merge them only when we find an empty line
|
# We also store text lines in a buffer and merge them only when we find an empty line
|
||||||
# indicating a new paragraph.
|
# indicating a new paragraph.
|
||||||
@@ -124,7 +87,7 @@ class ToLaTeX(Tokenizer):
|
|||||||
|
|
||||||
elif tType == self.T_SEP:
|
elif tType == self.T_SEP:
|
||||||
self.theResult += begText
|
self.theResult += begText
|
||||||
self.theResult += "%s\n" % tText
|
self.theResult += "%s\n" % self._escapeUnicode(tText)
|
||||||
self.theResult += endText
|
self.theResult += endText
|
||||||
|
|
||||||
elif tType == self.T_TEXT:
|
elif tType == self.T_TEXT:
|
||||||
|
|||||||
+10
-2
@@ -32,7 +32,7 @@ from nw.convert.file.markdown import MarkdownFile
|
|||||||
from nw.convert.file.latex import LaTeXFile
|
from nw.convert.file.latex import LaTeXFile
|
||||||
from nw.convert.file.concat import ConcatFile
|
from nw.convert.file.concat import ConcatFile
|
||||||
from nw.constants import nwFiles
|
from nw.constants import nwFiles
|
||||||
from nw.enum import nwItemType
|
from nw.enum import nwItemType, nwAlert
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -167,11 +167,19 @@ class GuiExport(QDialog):
|
|||||||
nDone += 1
|
nDone += 1
|
||||||
|
|
||||||
outFile.closeFile()
|
outFile.closeFile()
|
||||||
|
|
||||||
self.exportProgress.setValue(nDone)
|
self.exportProgress.setValue(nDone)
|
||||||
self.exportStatus.setText("Export to %s complete" % outFile.fileName)
|
self.exportStatus.setText("Export to %s complete" % outFile.fileName)
|
||||||
logger.verbose("Export to %s complete" % outFile.fileName)
|
logger.verbose("Export to %s complete" % outFile.fileName)
|
||||||
|
|
||||||
|
if eFormat == GuiExportMain.FMT_TEX:
|
||||||
|
# Check that encoding was successful
|
||||||
|
if outFile.texCodecFail:
|
||||||
|
self.theParent.makeAlert((
|
||||||
|
"Failed to escape unicode characters while writing LaTeX file. "
|
||||||
|
"The genrated .tex file may not build properly. "
|
||||||
|
"Make sure the python package 'latexcodec' is installed and working."
|
||||||
|
), nwAlert.WARN)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def _doClose(self):
|
def _doClose(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user