worldbank / ESG_gaps_research

See draft publication here: https://worldbank.github.io/ESG_gaps_research/
2 stars 5 forks source link

Trouble with mathjax #34

Open tgherzog opened 4 years ago

tgherzog commented 4 years ago

@tonyfujs @randrescastaneda

I'm having trouble regenerating the report on my local, and could use some help. When I build the entire report in R, then I see gibberish in place of math equations in Andres' appendix 2. But if I rebuild just appendix 2 in preview mode then the math equations appear correctly.

Here are steps to reproduce; I get almost (see below) the same result if I run in the IDE vs the command line:

git checkout 63b76e2
r -q -e 'bookdown::render_book("index.Rmd")'
...
Output created: docs/index.html
[1] "/Users/tim/ESG_gaps_research/docs/index.html"
...

My Appendix 2 now looks like this:

image

Now, I run bookdown on just the appendix file:

r -q -e 'bookdown::render_book("ESG_appendix2.Rmd", preview=TRUE)'
...
Output created: docs/appendix-coverage-analysis.html
[1] "/Users/tim/ESG_gaps_research/docs/appendix-coverage-analysis.html"
...

Now my Appendix 2 looks like this:

image

Interestingly, if I run bookdown::render_book from the RStudio IDE instead of from the command line the HTML output is slightly different, although what I see in my browser is exactly the same effect.

Here's the important part of the diff when I run broken::render_book from the IDE:

diff broken-ide working-ide
52,53d51
< <script src="libs/plotly-binding/plotly.js"></script>
< <script src="libs/typedarray/typedarray.min.js"></script>
55,58d52
< <link href="libs/crosstalk/css/crosstalk.css" rel="stylesheet" />
< <script src="libs/crosstalk/js/crosstalk.min.js"></script>
< <link href="libs/plotly-htmlwidgets-css/plotly-htmlwidgets.css" rel="stylesheet" />
< <script src="libs/plotly-main/plotly-latest.min.js"></script>
69a64,65
> <link href="libs/crosstalk/css/crosstalk.css" rel="stylesheet" />
> <script src="libs/crosstalk/js/crosstalk.min.js"></script>

Here's the same from when I run from the command line:

diff broken-cmdline working-cmdline
31,33c31,33
< <link href="libs/tufte-css/tufte.css" rel="stylesheet" />
< <link href="libs/tufte-css/envisioned.css" rel="stylesheet" />
< <link href="libs/msmb-css/msmb.css" rel="stylesheet" />
---
> <link href="libs/tufte-css-2015.12.29/tufte.css" rel="stylesheet" />
> <link href="libs/tufte-css-2015.12.29/envisioned.css" rel="stylesheet" />
> <link href="libs/msmb-css-0/msmb.css" rel="stylesheet" />
51,69c51,65
< <script src="libs/htmlwidgets/htmlwidgets.js"></script>
< <script src="libs/plotly-binding/plotly.js"></script>
< <script src="libs/typedarray/typedarray.min.js"></script>
< <script src="libs/jquery/jquery.min.js"></script>
< <link href="libs/crosstalk/css/crosstalk.css" rel="stylesheet" />
< <script src="libs/crosstalk/js/crosstalk.min.js"></script>
< <link href="libs/plotly-htmlwidgets-css/plotly-htmlwidgets.css" rel="stylesheet" />
< <script src="libs/plotly-main/plotly-latest.min.js"></script>
< <link href="libs/datatables-css/datatables-crosstalk.css" rel="stylesheet" />
< <script src="libs/datatables-binding/datatables.js"></script>
< <link href="libs/dt-core/css/jquery.dataTables.min.css" rel="stylesheet" />
< <link href="libs/dt-core/css/jquery.dataTables.extra.css" rel="stylesheet" />
< <script src="libs/dt-core/js/jquery.dataTables.min.js"></script>
< <link href="libs/dt-ext-fixedcolumns/css/fixedColumns.dataTables.min.css" rel="stylesheet" />
< <script src="libs/dt-ext-fixedcolumns/js/dataTables.fixedColumns.min.js"></script>
< <link href="libs/nouislider/jquery.nouislider.min.css" rel="stylesheet" />
< <script src="libs/nouislider/jquery.nouislider.min.js"></script>
< <link href="libs/selectize/selectize.bootstrap3.css" rel="stylesheet" />
< <script src="libs/selectize/selectize.min.js"></script>
---
> <script src="libs/htmlwidgets-1.5.1/htmlwidgets.js"></script>
> <script src="libs/jquery-1.12.4/jquery.min.js"></script>
> <link href="libs/datatables-css-0.0.0/datatables-crosstalk.css" rel="stylesheet" />
> <script src="libs/datatables-binding-0.11/datatables.js"></script>
> <link href="libs/dt-core-1.10.19/css/jquery.dataTables.min.css" rel="stylesheet" />
> <link href="libs/dt-core-1.10.19/css/jquery.dataTables.extra.css" rel="stylesheet" />
> <script src="libs/dt-core-1.10.19/js/jquery.dataTables.min.js"></script>
> <link href="libs/dt-ext-fixedcolumns-1.10.19/css/fixedColumns.dataTables.min.css" rel="stylesheet" />
> <script src="libs/dt-ext-fixedcolumns-1.10.19/js/dataTables.fixedColumns.min.js"></script>
> <link href="libs/nouislider-7.0.10/jquery.nouislider.min.css" rel="stylesheet" />
> <script src="libs/nouislider-7.0.10/jquery.nouislider.min.js"></script>
> <link href="libs/selectize-0.12.0/selectize.bootstrap3.css" rel="stylesheet" />
> <script src="libs/selectize-0.12.0/selectize.min.js"></script>
> <link href="libs/crosstalk-1.0.0/css/crosstalk.css" rel="stylesheet" />
> <script src="libs/crosstalk-1.0.0/js/crosstalk.min.js"></script>

Strange, isn't it? Can you reproduce this locally? Any idea what the problem might be?

tgherzog commented 4 years ago

@randrescastaneda @tonyfujs I've been able to further isolate the problem, although I still don't know how to fix it. If I run this command in the IDE:

bookdown::render_book("index.Rmd")

and then manually edit docs/appendix-coverage-analysis.html to remove line 58:

<script src="libs/plotly-main/plotly-latest.min.js"></script>

then the math equations work correctly for me. Note that line 58 is one of 4 lines of HTML code that are only generated for the complete book not when the appendix is generated by itself. But this is the only one of the 4 lines that seems to impact the equations.

tgherzog commented 3 years ago

I added a function mathjax_fix which will remove the line above (requires that the "stringr" library be installed). This can be run from the console after an HTML build like this:

source("R/report.R")
mathjax_fix()

Ideally, this could be run as a post-process function by bookdown. Well actually more ideally would be to fix the bug in the first place ;)