JelteF / PyLaTeX

A Python library for creating LaTeX files
https://jeltef.github.io/PyLaTeX/
MIT License
2.24k stars 286 forks source link

graphicx package not being imported #331

Closed petaflot closed 1 month ago

petaflot commented 3 years ago

steps to reproduce:

1) take example from https://jeltef.github.io/PyLaTeX/current/examples/complex_report.html 2) replace PNG pictures by a cute kitten 3) comment out Header image code 4) add cheque images not to doc, but to customer or branch (relevant section of the code must be moved around and somewhat indented) 5) notice how latex \usepackage{graphicx}% is now missing from the latex output : the cute kittens are gone.

JelteF commented 3 years ago

It's not clear to me what the problem is. You replaced the pictures in the header with a kitten. and then commented that code out. Then it makes sense that the kittens are gone, because you commented them out.

In any case, without a clear error and code I cannot help you. Feel free to update the issue with more detail.

petaflot commented 3 years ago

I didn't comment these kitten out ; just the kitten in the header (which caused \usepackage{grpahicx}" to be inserted in the tex file.

these kittens, without the the image in the header, are shown as text (like [width=50px],path=... or sth similar ; it's hard to see because the text that is displayed were there should be images is overlapping and made unreadable

JelteF commented 3 years ago

Like I said your description of the issue is not clear enough for me to provide help. There's no code, and no resulting tex file. Could you please provide those?

On Mon, 5 Jul 2021, 00:10 Engrenage, @.***> wrote:

I didn't comment these kitten out ; just the kitten in the header (which caused \usepackage{grpahicx}" to be inserted in the tex file.

these kittens, without the the image in the header, are shown as text (like [width=50px],path=... or sth similar ; it's hard to see because the text that is displayed were there should be images is overlapping and made unreadable

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/JelteF/PyLaTeX/issues/331#issuecomment-873672023, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAI3YJUXBVOGRXEOF6Z6RLDTWDL33ANCNFSM47ZDUAVA .

neoglez commented 1 year ago

I have the same issue:

doc = Document()

with doc.create(Section('Possible PyLatex Bug')):
    with doc.create(Tabular("|c|c|", booktabs=True)) as table:                
            image_paths_multi_columns =  [
                  MultiColumn(1, align='l', data=StandAloneGraphic(
                      filename='sample-logo.png')),
                  MultiColumn(1, align='l', data=StandAloneGraphic(
                      filename='sample-logo.png'))
             ]

            table.add_row(image_paths_multi_columns)

The problem is that the Table object does not propagate its descendants packages:

for c in cells:
      if isinstance(c, LatexObject):
          for p in c.packages:
              self.packages.add(p)

The issue appears when the c is a MultiColumn with at least one descendant, e.g., StandAloneGraphic. Because the iteration is performed only at the top level, adding the descendant packages fails.