lecture-datascience.myst icon indicating copy to clipboard operation
lecture-datascience.myst copied to clipboard

ENH: Enable PDF book style build via LaTeX

Open AakashGfude opened this issue 3 years ago • 28 comments

This PR enables the book style PDF to be built via LaTeX.

Changes:

Upgrading to mathjax v3 to use textmacros was necessary, to escape _ inside \text{} as it is a special character. https://github.com/QuantEcon/lecture-datascience.myst/compare/pdf-changes?expand=1#diff-596037ac6201ed91873ef81f374bc604c6c1f0a4d56833e749433585288d7b1eR135

NOTE that while using _ or any special characters inside \text{} we need to escape it. Like its done in this PR by using \_ instead of _

{align*} is an environment, which throws errors in latex, when its inside another environment like $$ . Using {aligned} instead is the way to go.

AakashGfude avatar Oct 18 '21 23:10 AakashGfude

{align*} is an environment, which throws errors in latex, when its inside another environment like $$ . Using {aligned} instead is the way to go.

Thanks @AakashGfude 👍 -- this is because aligned is not a full math environment so can be used within the $$. I will add an update to https://manual.quantecon.org/writing/styleguide.html#mathematical-notation with a better explanation for the quantecon style guide.

mmcky avatar Oct 18 '21 23:10 mmcky

  • [x] update environment.yml to include quantecon-book-theme==0.2.8

Actually this is taken care of for automatic minor version updates:

    - quantecon-book-theme>=0.2.5,<0.3.0

mmcky avatar Oct 19 '21 00:10 mmcky

quantecon-book-theme 0.2.8 is now released.

AakashGfude avatar Oct 19 '21 00:10 AakashGfude

@AakashGfude is there a package I need to add to support the image conversion?

mmcky avatar Oct 19 '21 01:10 mmcky

@AakashGfude do the image file references need support for folders?

../_build/jupyter_execute/working_with_text_52_0.png

or is this directory a flat collection if images?

mmcky avatar Oct 19 '21 03:10 mmcky

@AakashGfude I just ran this branch locally -- it seems to build the pdf. Perhaps the images are not getting "written" in the server environment (or saved from the execution steps). Hmm ....

Actually my local jupyter_execute is organised in folders

lectures/_build/jupyter_execute  adjust-toc ✔                                                                                         2m  
▶ ls
applications        index.py            pandas              python_fundamentals theme
index.ipynb         introduction        problem_sets        scientific

mmcky avatar Oct 19 '21 03:10 mmcky

@AakashGfude I have opened https://github.com/QuantEcon/lecture-datascience.myst/pull/194 to update _toc.yml into jb-book format for better pdflatex outputs.

  • [ ] merge https://github.com/QuantEcon/lecture-datascience.myst/pull/194

mmcky avatar Oct 19 '21 04:10 mmcky

@mmcky , i think the path is different in server than in local? Is their an artifact we can download?

AakashGfude avatar Oct 19 '21 04:10 AakashGfude

@mmcky actually the path generated is wrong altogether, as the file it is trying to find, for example, is '../_build/jupyter_execute/plotting_5_1.png' but the file is in path jupyter_execute/scientific/plotting_5_1.png

AakashGfude avatar Oct 19 '21 04:10 AakashGfude

yeah -- that's right. It seems to be missing the nested folder (scientific) right?

mmcky avatar Oct 19 '21 04:10 mmcky

yeah -- that's right. It seems to be missing the nested folder (scientific) right?

@mmcky But also, locally it is noindent\sphinxincludegraphics{{plotting_5_1}.png} in tex file, . the images ideally get copied to where the tex file is in the _build/latex folder and it accesses that one instead of the one in jupyter_execute

AakashGfude avatar Oct 19 '21 04:10 AakashGfude

yeah -- that's right. It seems to be missing the nested folder (scientific) right?

@mmcky But also, locally it is noindent\sphinxincludegraphics{{plotting_5_1}.png} in tex file, . the images ideally get copied to where the tex file is in the _build/latex folder and it accesses that one instead of the one in jupyter_execute

How do they avoid conflicts -- is that _5_1 in chapter 5 section 1? Or just a numbering system in that file as in (-)

mmcky avatar Oct 19 '21 05:10 mmcky

@AakashGfude the _build folder is available

https://github.com/QuantEcon/lecture-datascience.myst/actions/runs/1357596935

under artifacts

mmcky avatar Oct 19 '21 05:10 mmcky

@AakashGfude so the _build folder from github actions doesn't have any of the png images in _build/latex unlike the local build. So the images are not getting copied over (as you say).

mmcky avatar Oct 19 '21 05:10 mmcky

@AakashGfude so the _build folder from github actions doesn't have any of the png images in _build/latex unlike the local build. So the images are not getting copied over (as you say).

Hmm, will check what is 'cause' and what is 'effect' here

AakashGfude avatar Oct 19 '21 05:10 AakashGfude

@AakashGfude so the _build folder from github actions doesn't have any of the png images in _build/latex unlike the local build. So the images are not getting copied over (as you say).

Hmm, will check what is 'cause' and what is 'effect' here

@AakashGfude what confuses me is that the other repos are building on github actions just fine. So it must be something to do with this repo structure such as nested folders.

mmcky avatar Oct 19 '21 08:10 mmcky

@mmcky you are right. it was a nested folder issue, when a different output path is specified using --path-output. The bug was on the Myst-NB side: https://github.com/executablebooks/MyST-NB/issues/367

The following PR should fix it https://github.com/executablebooks/MyST-NB/pull/368

AakashGfude avatar Oct 21 '21 22:10 AakashGfude

thanks @AakashGfude for your input here.

@jlperla we have made some improvements to the stack. I will release a new version of myst-nb which includes a fix that will enable the book style pdf for this project.

  • [ ] merge after new myst-nb==0.13.2 is released https://github.com/executablebooks/MyST-NB/pull/369

mmcky avatar Oct 25 '21 05:10 mmcky

@mmcky @AakashGfude Sounds great! Feel free to merge when you are happy with it

jlperla avatar Oct 25 '21 14:10 jlperla

@AakashGfude can you review these conflicts

mmcky avatar Dec 06 '21 04:12 mmcky

This PR will break the Plotly graph as it uses mathjaxv3 instead of v2. The reason for this is mentioned in this PR description. Have to find some common ground before merging this.

AakashGfude avatar Dec 06 '21 06:12 AakashGfude

@AakashGfude just ping me once this is ready for review and we can then merge once you're happy.

mmcky avatar Dec 15 '21 06:12 mmcky

@mmcky I am not sure what is causing this. But the netlify link is not rendering plotly figures. but my local environment is. tried to mimic the packages.

AakashGfude avatar Dec 15 '21 06:12 AakashGfude

This PR has been halted from merging, because of HTML build failing. Which is caused by the server of Canadian government, geolocation service being currently down. https://www.nrcan.gc.ca/science-and-data/science-and-research/earth-sciences/geography/topographic-information/web-services/geolocation-service/17304

AakashGfude avatar Dec 18 '21 03:12 AakashGfude

@AakashGfude hopefully this server issue is now resolved. So could you re-trigger the CI to check.

mmcky avatar Feb 09 '22 05:02 mmcky

@mmcky I did run it again, and got the following error. working_with_text.log

Some nltk issue, 9omw-1.4 not found.

AakashGfude avatar Feb 09 '22 06:02 AakashGfude

@mmcky I did run it again, and got the following error. working_with_text.log

Some nltk issue, 9omw-1.4 not found.

Is this on your local? I saw the CI last ran on 3rd Jan.

Roger that. @jbrightuniverse any ideas on how to resolve this nltk issue?

mmcky avatar Feb 09 '22 06:02 mmcky

according to those logs:

  Resource [93momw-1.4[0m not found.
  Please use the NLTK Downloader to obtain the resource:

  [31m>>> import nltk
  >>> nltk.download('omw-1.4')
  [0m
  For more information see: https://www.nltk.org/data.html

it seems that a language set is missing? the logs claim executing that line at some point in the build would solve it; I'm not familiar with the codebase so I'm not sure if that already happens or if the set is expected to already be there. Also notable is the logs claim:

  Attempted to load [93mcorpora/omw-1.4.zip/omw-1.4/[0m

  Searched in:
    - '/home/runner/nltk_data'
    - '/usr/share/miniconda3/envs/lecture-datascience/nltk_data'
    - '/usr/share/miniconda3/envs/lecture-datascience/share/nltk_data'
    - '/usr/share/miniconda3/envs/lecture-datascience/lib/nltk_data'
    - '/usr/share/nltk_data'
    - '/usr/local/share/nltk_data'
    - '/usr/lib/nltk_data'
    - '/usr/local/lib/nltk_data'

jbrightuniverse avatar Feb 09 '22 06:02 jbrightuniverse