Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Enable PDF book style build via LaTeX #193

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open

Conversation

AakashGfude
Copy link
Member

@AakashGfude AakashGfude commented Oct 18, 2021

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.

@mmcky
Copy link
Contributor

mmcky commented Oct 18, 2021

{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.

@github-actions github-actions bot temporarily deployed to commit October 18, 2021 23:44 Inactive
TeX:
extensions: ["autobold.js"]
Macros:
"argmax" : "arg\\,max"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AakashGfude I presume these aren't required for datascience

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are already added in quantecon-book-theme for mathjax v3. https://github.com/QuantEcon/quantecon-book-theme/blob/master/quantecon_book_theme/layout.html#L10 .

Since, there is no variable in sphinx to add configuration for mathjax3 in config file. I think it should be introduced in sphinxv4 though.

Copy link
Contributor

@mmcky mmcky Oct 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the new variable in sphinx version 4+ is mathjax3_config

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AakashGfude I have opened a issue to track that inclusion

QuantEcon/quantecon-book-theme#167

@@ -132,14 +132,14 @@ that best fit the data.

$\epsilon$ is the error term. It would be unusual for the observed
$\log(\text{price})$ to be an exact linear function of
$\text{sqft_living}$. The error term captures the deviation of
$\log(\text{price})$ from a linear function of $\text{sqft_living}$.
$\text{sqft\_living}$. The error term captures the deviation of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AakashGfude just for clarity for when I update the style guide we need to escape the _ right?

This change QuantEcon/quantecon-book-theme@ec8d8c8 will then enable the correct Tex to be processed by mathjax.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if we want to write a literal underscore, then we will have to escape it like that. http://docs.mathjax.org/en/latest/input/tex/extensions/textmacros.html#quoted-special-characters . I was about to comment about mentioning textmacros in the style guide as well http://docs.mathjax.org/en/latest/input/tex/extensions/textmacros.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would be great -- can you remind me or open an issue on: QuantEcon.manual

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmcky what is QuantEcon.manual ?

@mmcky mmcky changed the title Changes necessary for pdf build ENH: Enabled PDF book style build via LaTeX Oct 18, 2021
@mmcky mmcky changed the title ENH: Enabled PDF book style build via LaTeX ENH: Enable PDF book style build via LaTeX Oct 18, 2021
@github-actions github-actions bot temporarily deployed to commit October 19, 2021 00:06 Inactive
@mmcky
Copy link
Contributor

mmcky commented Oct 19, 2021

  • 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

@AakashGfude
Copy link
Member Author

quantecon-book-theme 0.2.8 is now released.

@mmcky
Copy link
Contributor

mmcky commented Oct 19, 2021

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

@mmcky
Copy link
Contributor

mmcky commented Oct 19, 2021

@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
Copy link
Contributor

mmcky commented Oct 19, 2021

@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
Copy link
Contributor

mmcky commented Oct 19, 2021

@AakashGfude I have opened #194 to update _toc.yml into jb-book format for better pdflatex outputs.

@AakashGfude
Copy link
Member Author

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

@AakashGfude
Copy link
Member Author

AakashGfude commented Oct 19, 2021

@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

@mmcky
Copy link
Contributor

mmcky commented Oct 19, 2021

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

@AakashGfude
Copy link
Member Author

AakashGfude commented Oct 19, 2021

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

@mmcky
Copy link
Contributor

mmcky commented Oct 19, 2021

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
Copy link
Contributor

mmcky commented Oct 19, 2021

@AakashGfude the _build folder is available

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

under artifacts

@mmcky
Copy link
Contributor

mmcky commented Oct 19, 2021

@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).

@AakashGfude
Copy link
Member Author

AakashGfude commented Oct 19, 2021

@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

@mmcky
Copy link
Contributor

mmcky commented Oct 19, 2021

@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.

@github-actions github-actions bot temporarily deployed to commit December 16, 2021 00:49 Inactive
@github-actions github-actions bot temporarily deployed to commit December 16, 2021 01:01 Inactive
@github-actions github-actions bot temporarily deployed to commit December 16, 2021 01:14 Inactive
@github-actions github-actions bot temporarily deployed to commit December 16, 2021 01:30 Inactive
@github-actions github-actions bot temporarily deployed to commit December 16, 2021 02:01 Inactive
@github-actions github-actions bot temporarily deployed to commit December 16, 2021 05:27 Inactive
@github-actions github-actions bot temporarily deployed to commit December 16, 2021 05:40 Inactive
@github-actions github-actions bot temporarily deployed to commit December 16, 2021 05:48 Inactive
@github-actions github-actions bot temporarily deployed to commit December 16, 2021 12:30 Inactive
@github-actions github-actions bot temporarily deployed to commit December 16, 2021 13:18 Inactive
@github-actions github-actions bot temporarily deployed to commit December 16, 2021 23:42 Inactive
@AakashGfude AakashGfude marked this pull request as ready for review December 17, 2021 02:45
@AakashGfude
Copy link
Member Author

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

@mmcky
Copy link
Contributor

mmcky commented Feb 9, 2022

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

@AakashGfude
Copy link
Member Author

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

Some nltk issue, 9omw-1.4 not found.

@mmcky
Copy link
Contributor

mmcky commented Feb 9, 2022

@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?

@jbrightuniverse
Copy link
Collaborator

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants