njtierney / rmd4sci

Rmarkdown for Scientists
https://rmd4sci.njtierney.com/
Other
127 stars 40 forks source link

add downloadable book version? #27

Open apreshill opened 5 years ago

apreshill commented 5 years ago

Hey @njtierney,

Not that you need to-you could disable that option all together. But you can add an epub or pdf version to your .travis.yml like this example:

https://github.com/tidyverse/style/blob/e2d76307a7ec8feecb4b3da72501687b7f4ba770/.travis.yml#L17-L18

I would offer a PR but I don't know tic and am afraid of screwing up your build!

Alison

njtierney commented 5 years ago

Heya @apreshill :wave:

Ah, the broken download link has been bothering me for a while! Thank you for this. Let's see how it goes.

😄

njtierney commented 5 years ago

well this failed in a way I was not expecting: https://travis-ci.org/njtierney/rmd4sci/builds/570664147#L1252

24.19s$ Rscript -e "bookdown::render_book('index.Rmd', 'bookdown::pdf_book', quiet = TRUE)"
!!! Error: Ghostscript exited with error code 127!
!!! Error: Ghostscript exited with error code 127!

Have you seen that error before?

Also, I used to use tic, but once you showed me your recipe for getting bookdown to publish via netlify it worked a charm, and I removed tic. https://github.com/njtierney/rmd4sci/search?q=tic&type=Code

apreshill commented 5 years ago

Blurg! No I haven't seen it, but a google search suggests (to me) that Ghostscript may be associated with the PDF output. When I tried to build the PDF book locally, I fail with this error:

tlmgr search --file --global '/Source Code Pro[.](tfm|afm|mf|otf)'
! Package fontspec Error: The font "Source Code Pro" cannot be found.

! kpathsea:make_tex: Invalid filename `Source Code Pro', contains ' '

Error: Failed to compile rmd4sci.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See rmd4sci.log for more info.
In addition: Warning message:
In parse_packages(logfile, quiet = c(TRUE, FALSE, FALSE)) :
  Failed to find a package that contains Source Code Pro[.](tfm|afm|mf|otf)
Execution halted

Exited with status 1.

I would bet if you removed that build from your script it would work.

njtierney commented 5 years ago

Ah, thanks for tracing that issue down, @apreshill :)

Let's see how this one goes.

njtierney commented 5 years ago

OK so removing the PDF build fixed it :tada:

Next steps will be getting the PDF build working and the MOBI version as well.

murraycadzow commented 4 years ago

I just ran into the same issue as @apreshill plus a few other fonts seemed to be missing on my machine when building but found that this managed to solve it for me (on ubuntu)

mkdir ~/.fonts
git clone git://github.com/google/fonts.git ~/.fonts/google-fonts 
fc-cache -f

from https://gist.github.com/keeferrourke/d29bf364bd292c78cf774a5c37a791db#gistcomment-2716262

yihui commented 4 years ago

!!! Error: Ghostscript exited with error code 127!

@njtierney Here is the fix to this issue: https://github.com/rstudio/bookdown-demo/commit/ae54659a339acf54477690a6b24ced92f6f8b8a3

njtierney commented 4 years ago

Thanks, @yihui - it works for EPUB now, but it looks like PDF causes some issues still: https://travis-ci.org/github/njtierney/rmd4sci/jobs/725481117#L4502

50% there though, thanks for your help, @yihui :)

yihui commented 4 years ago

The problem that you mentioned seems to be for EPUB instead of PDF.

[WARNING] Could not convert TeX math '
  Y \sim X\beta_0 + X\beta_1 + \epsilon \tag{1}
  ', rendering as TeX:

                     ^
  unexpected "{"
  expecting "%", "\\label", "\\nonumber" or whitespace
[1] "/home/travis/build/njtierney/rmd4sci/_book/rmd4sci.epub"

It was caused by \tag{}:

https://github.com/njtierney/rmd4sci/blob/ce9d405713435d2ff42bb54d972dac72e59ce7e1/caption-reference-eqn.Rmd#L30-L32

I don't know why Pandoc doesn't support \tag{}. Perhaps you can drop this way of providing equation numbers, and only mention the first way.

yihui commented 4 years ago

You didn't seem to build PDF at all: https://github.com/njtierney/rmd4sci/blob/1c734e26fe74247a76db40452701fa605a157b69/.travis.yml#L24

njtierney commented 4 years ago

Ack, sorry for that, @yihui, thanks for being a fresh pair of eyes. I'll more thoroughly read my travis build next time 🙂

yihui commented 4 years ago

To be able to build PDF, you have to either delete the font specifications (i.e. use default fonts): https://github.com/njtierney/rmd4sci/blob/059dd5af508cb899a2f32e36aa8bc72eef5d36cb/index.Rmd#L13-L14 https://github.com/njtierney/rmd4sci/blob/059dd5af508cb899a2f32e36aa8bc72eef5d36cb/latex/preamble.tex#L5 or actually install the fonts, e.g. follow @murraycadzow's tip above. Cloning and installing all Google Fonts sounds like an overkill to me, since you only need two of them. If I were you, I won't bother doing this.

The third option is to use fonts available on Ubuntu, and I believe there are many, but the downside is for people who do not use Ubuntu, they may not be able to build PDF by themselves. It depends on how much you really care about the typefaces in PDF.