Comments (16)
You should probably use lualatex or xetex as the compiler then. See #47
from pylatex.
Thanks, I did not know about it)
But I still get the error:
"! String contains an invalid utf-8 sequence."
I think this happens because the generated tex file is not in utf encoding.
When I create a tex file myself - pdflatex encodes it normally.
from pylatex.
Hmm this sounds strange, are you using python 3 or python 2?
And could you show a simple example that doesn't work?
from pylatex.
I'm using Python 3.
Code example:
https://gist.github.com/winogradoff/2544b3d3b40a98c44e53
And yes, I'm using packages argument from the pull request:
#58
from pylatex.
I tested some things with your snippet after downloading cyrillyc packages for latex. The key fix seems to be adding the babel package.
You can do this by doing this after initializing the Document
object:
doc.packages.add(Package('babel', options='russian'))
Could you confirm this? (this should work without your new commits)
from pylatex.
Something else that might help if you are having trouble is setting the fontenc to T2A, T2B or T2C. See page 5 of this document for the differences http://latex-project.org/guides/cyrguide.pdf. For me however, the babel package uses one that works automatically.
from pylatex.
I have created a pdf-file with the Cyrillic alphabet.
Just deleted this package from my code:
Package ('inputenc', options = ['utf8'])
https://gist.github.com/winogradoff/2544b3d3b40a98c44e53
Your library creates a tex-file in non-unicode encoding.
It would be better to use utf-8 support like this (for Python 2 and Python 3):
http://stackoverflow.com/questions/10971033/backporting-python-3-openencoding-utf-8-to-python-2
from pylatex.
Sorry, I might have been unclear. What I meant was code like this:
doc = Document(
author=doc_author,
date=current_date,
title=doc_title,
maketitle=True,
)
doc.packages.add(Package('babel', options=['russian']))
Since the Package('inputenc', options='utf8')
is added by default the encoding should be interpreted correctly.
from pylatex.
That way it doesn't work. Because the file *.tex in non-unicode encoding.
It works fine until the text contains unicode characters.
You should write files in unicode for wider support of encodings:
http://stackoverflow.com/questions/10971033/backporting-python-3-openencoding-utf-8-to-python-2
from pylatex.
I really don't think that is the case. Definitely not in Python 3 at least. Could you try my code above with some Cyrillic characters added and tell me the error (and show the code)? Since it worked on my machine.
from pylatex.
Try with this file:
https://drive.google.com/file/d/0B3qRZwrY7kcgYm5FT0hyS0gtRWs/view?usp=sharing
And then try to encode * .tex file in utf-8 and run pdflatex from the console.
Then pdflatex should make PDF-file.
from pylatex.
This works fine for Python 3:
def generate_tex(self, filename=''):
"""Generates a .tex file.
:param filename: the name of the file
:type filename: str
"""
filename = self.select_filename(filename)
with open(filename + '.tex', 'w', encoding='utf-8') as newf:
self.dump(newf)
from pylatex.
Your code worked fine for me. I think I know where the bug is coming from. This is what the python documentation says:
In text mode, if encoding is not specified the encoding used is platform dependent: locale.getpreferredencoding(False) is called to get the current locale encoding. (For reading and writing raw bytes use binary mode and leave encoding unspecified.)
It probably works on my machine because my default locale is UTF8. If you send a pull request with the change I will accept it when it passes Travis. Please add it to the changelog as well as an item under Fixed.
from pylatex.
Wow. Thanks for the info.
I will try this week to make a pull request.
from pylatex.
I fixed it myself since it was such a small change.
from pylatex.
Thank you.
from pylatex.
Related Issues (20)
- Add sympy support
- Texify to tableofcontents HOT 1
- fontenc and inputenc should not be included
- Store the generated PDF in byteIO
- How to properly add math and refs to captions
- No LaTex compiler was found (Windows 10) HOT 8
- How to to compile .tex file? HOT 2
- File not found for files with dots in relative or absolute path to file
- How to Specify LaTeX Compiler
- "PermissionError: [WinError 5] Access is denied" with document.generate_pdf()
- Adding pandas dataframes to pylatex sections breaks with pandas 2.0
- Negative values in TextBlock
- Two-Column document HOT 1
- Question: Tiny text size HOT 1
- Python 3.12 install fails HOT 2
- Missing Options Paramter in Section classes
- Proposal for `add_item`
- how add txt file content to tex file ?
- cannot use bytes as filename
- Research
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pylatex.