question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when unicode character with add_image

See original GitHub issue

Hello, The first code below is working, but the second raises an error. Of course, both /home/mth/nounicode.jpg and /home/mth/unicodé.jpg exist (and both are the same duplicate picture).

#!/usr/bin/env python
# coding: utf-8

from pylatex import Document, Figure

doc = Document()

with doc.create(Figure(position='h!')) as kitten_pic:
    kitten_pic.add_image('/home/mth/nounicode.jpg')     # No problem with this name

doc.generate_pdf('toto', clean_tex=False)
#!/usr/bin/env python
# coding: utf-8

from pylatex import Document, Figure

doc = Document()

with doc.create(Figure(position='h!')) as kitten_pic:
    kitten_pic.add_image('/home/mth/unicodé.jpg')        # The name with é raises an error

doc.generate_pdf('toto', clean_tex=False)
>>> 
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/pylatex/document.py", line 228, in generate_pdf
    stderr=subprocess.STDOUT)
  File "/usr/lib/python3.4/subprocess.py", line 620, in check_output
    raise CalledProcessError(retcode, process.args, output=output)
subprocess.CalledProcessError: Command '['latexmk', '--pdf', '--interaction=nonstopmode', 'toto.tex']' returned non-zero exit status 12

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/mth/Pb accents.py", line 11, in <module>
    doc.generate_pdf('toto', clean_tex=False)
  File "/usr/local/lib/python3.4/dist-packages/pylatex/document.py", line 239, in generate_pdf
    print(e.output.decode())
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 3116: invalid continuation byte

In the log file, I find this :

LaTeX Warning: File `/home/mth/unicod\IeC {\'e}.jpg' not found on input lin
e 17.


! Package pdftex.def Error: File `/home/mth/unicod\E9.jpg' not found.

See the pdftex.def package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.17 ...0.8\textwidth]{/home/mth/unicodé.jpg}
                                                  %
Using draft setting for this image.

Would you have a clue to how I could manage this kind of situation ? By the way, thank you for your work !

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
JelteFcommented, Jul 26, 2017

No problem. Thanks for the info. I’ll leave the issue open for now and will maybe fix it myself using your snippets in the future when I have some time.

0reactions
mth31commented, Jul 26, 2017

I’m afraid I can’t do that. I have no idea how to create a pull request, and I am an amateur in python. However I watched in the code, and I would suggest to add this lines in the class StandAloneGraphic from figure.py, first in the def __init__ function :

if not all(ord(char) < 128 for char in filename):
    packages.add(Package('grffile', options=['encoding', 'filenameencoding=utf8']))

But I’m not sure if packages.add will work (in my case, I was using doc.packages.add instead).

Also, what if someone doesn’t use utf8 as encoding but something else ? (might be rare though).

I’m afraid that’s all I can do myself. Thank you very much, sorry I can’t help more.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unicode character in image filename makes sphinx crash #2395
Unicode character in image filename makes sphinx crash #2395 ... The Error is related to line 203 in sphinx.util.i18n.
Read more >
unicode characters in image URL - 404 - Stack Overflow
I am trying to open an image that has Latin characters in its name ... mysite.com/images/113_Atl%C3%A9tico%20Madrid.png I got 404 error.
Read more >
U+2069 error when adding image in TeXShop - TeX
I am trying to add an image into the document on TeXShop but keep seeing this error: Package inputenc Error: Unicode character (U+2069) ......
Read more >
Add image from my files - General Usage - Julia Discourse
I'm trying to load an image that I have on my computer, but I get this error … someone can audare me …...
Read more >
How to stamp image on existing PDF and create an anchor?
addImage (image); stamper.close();. Any idea how to do this? Posted on StackOverflow on Nov ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found