abdullahkhalids / qecft

The book A Methods Focused Guide to Quantum Error Correction and Fault-Tolerant Quantum Computation
Other
17 stars 6 forks source link

Add script to make PDF book from HTML #13

Closed schance995 closed 1 year ago

schance995 commented 1 year ago

Playwright was chosen because weasyprint cannot render Javascript. On my Arch Linux laptop it takes ~2 seconds to load the page with hardware acceleration and ~130 seconds without hardware acceleration.

abdullahkhalids commented 1 year ago

Thank you for the pull request. I tested it on my computer. A few issues.

image

I see this is because you are using node for mathjax. The install steps for this are missing. But do we need to do this? Node is a pretty heavy install requirement. Can we just use the existing online script to render the page?

abdullahkhalids commented 1 year ago

About point 2. I played around with it. I commented out the mathjax line

script["src"] = script["src"].replace("https://cdn.jsdelivr.net/npm/mathjax@3.0.0/", "node_modules/mathjax/")

and down below I changed

    page.goto(html, wait_until='load')
    time.sleep(10)

That seems to give enough time for the mathjax to load. I don't know if 'load' is the correct argument here. Maybe not the nicest way of doing this, but it does work. Maybe there is a better way.

schance995 commented 1 year ago

About point 2. I played around with it. I commented out the mathjax line

script["src"] = script["src"].replace("https://cdn.jsdelivr.net/npm/mathjax@3.0.0/", "node_modules/mathjax/")

and down below I changed

    page.goto(html, wait_until='load')
    time.sleep(10)

That seems to give enough time for the mathjax to load. I don't know if 'load' is the correct argument here. Maybe not the nicest way of doing this, but it does work. Maybe there is a better way.

I tested this and it works for me. I think it's the best way without writing more Javascript to hook into the end of Mathjax loading.

schance995 commented 1 year ago
* I think `lxml` library is also required, but not present in requirements.txt. I had to install it for the code to run.

I will add this to requirements.txt.

* How can we move the page numbers to either the center or to the center right like is common in books?

The footer_template argument needs to be styled. It's not exactly straightforward, see https://github.com/microsoft/playwright/issues/14441#issuecomment-1259718342

* Can you also add some code, showing how to add and remove css files? This can be commented out for now. For the actual build I would like to change fonts and colors etc to be print friendly.

Currently the book.html file uses the same CSS files as the web version. I can change the code to use a list of CSS files instead of (or along with) those used in the web version.

abdullahkhalids commented 1 year ago

For the footer, I played around with it a bit. This works well enough, to look decent. Kindly add this.

             footer_template='<span class="pageNumber" style="position: absolute; left: 62%; font-size: 10px;"></span>',
             margin={
                 "top": "1cm",
                 "right": "2cm",
                 "bottom": "1cm",
                 "left": "2cm",
             })