vkbo / novelWriter

novelWriter is an open source plain text editor designed for writing novels. It supports a minimal markdown-like syntax for formatting text. It is written with Python 3 (3.9+) and Qt 5 (5.15) for cross-platform support.
https://novelwriter.io
GNU General Public License v3.0
2.05k stars 106 forks source link

Unicode characters are not handled properly in LaTeX exports #101

Closed johnblommers closed 4 years ago

johnblommers commented 4 years ago

I've placed the characters π (π) and → (→) in a novelWriter document. When I export to LaTeX and attempt PDF conversion using TeXshop two errors present themselves:

./Dick_and_Jane.tex:66: Package inputenc Error: Unicode character → (U+2192)
(inputenc)                not set up for use with LaTeX.

See the inputenc package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.66 Jack and Jill →
                       the hill to fetch a pail of water.
? 

./Dick_and_Jane.tex:68: Package inputenc Error: Unicode character π (U+03C0)
(inputenc)                not set up for use with LaTeX.

See the inputenc package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                   

l.68 Puff likes to eat π
                          just like humans.

The two unicode characters don't appear in the PDF output after we press Return twice to bypass the error messages.

I had thought the matter resolved with the addition of the latexcodec but I think I've jumped the gun and tested this prematurely.

vkbo commented 4 years ago

The latexcodec documentation states that it isn't complete. I suppose all we can do is identify the problems and add them to the replacement dictionary manually, or report them to the package developers.

I will add these two, and check a few others of similar type.

johnblommers commented 4 years ago

I've found a workaround. If the intention is to export to LaTeX then the writer can simply insert the LaTeX code for the symbols they want. So:

novelWriter already passes the LaTeX codes directly into the LaTeX output file where it will present correctly when converted to PDF. I'm a Gummi fan and this worked for me.

vkbo commented 4 years ago

Yes, the latexcodec package leaves already correct LaTeX formatted text alone.

Only paragraphs and heading text is encoded with this package though, but this is certainly a workable solution if LaTeX is the only export used. I will add it to the documentation.

johnblommers commented 4 years ago

Comment.

Writers that include LaTeX in their novels are probably a rare breed and will know how to handle problems they encounter using it in novelWriter.

For example. I created a LaTeX math formula that contained subscripts like this:

$$f(x)=a_{0}+a_{1}x$$

but on exporting this with novelWriter the subscript character _ found itself escaped as \_ in the .tex export file. The workaround is to instead use the \sb LaTeX syntax:

$$f(x)=a\sb{0}+a\sb{1}x$$

vkbo commented 4 years ago

Yeah, that's far beyond what is intended usage of novelWriter. It's for writing plain text. The LaTeX export is only intended for generating PDFs of plain text quickly.

vkbo commented 4 years ago

LaTeX export will not be included in the new Project Build Tool, and the current Export tool will be removed. This issue will therefore not be addressed. Closing it.