rstudio / bookdown-demo

A minimal book example using bookdown
https://bookdown.org/yihui/bookdown-demo
Creative Commons Zero v1.0 Universal
504 stars 1.34k forks source link

`bookdown-demo_files/figure-latex/nice-fig-1' not found #3

Closed melindahiggins2000 closed 8 years ago

melindahiggins2000 commented 8 years ago

I am having good luck getting both HTML and EPUB formats to work when running "Build Book" for the bookdown-demo. However, when compiling to PDF, I get the following errors (shown in the Build Book window). My sessionInfo() is also listed below. I am running RStudio Version 0.99.1128 on Windows-10 with MiKTeX v2.9.

Note: when compiling to HTML I do get the "nice-fig-1.png" figure created into my ".._book\bookdown-demo_files\figure-html\" directory just fine.

Any help is appreciated.

Thank you, Melinda Higgins

----- Build Book errors -----------------------------------------------------------
latexmk.exe: MiKTeX encountered an internal error.
! LaTeX Error: File `bookdown-demo_files/figure-latex/nice-fig-1' not found.

Error: Failed to compile bookdown-demo.tex. See bookdown-demo.log for more info.
In addition: Warning messages:
1: running command '"C:\PROGRA~2\MIKTEX~1.9\miktex\bin\latexmk.exe" -pdf -latexoption=-halt-on-error -interaction=batchmode -pdflatex="pdflatex" "bookdown-demo.tex"' had status 1 
2: running command '"C:\PROGRA~2\MIKTEX~1.9\miktex\bin\latexmk.exe" -v' had status 1 
Execution halted

Exited with status 1.
----- Session Info -------------------------------------------
> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets 
[6] methods   base     

other attached packages:
[1] knitr_1.12.3    devtools_1.10.0

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.4       bookdown_0.0.60   withr_1.0.1      
 [4] digest_0.6.9      mime_0.4          R6_2.1.2         
 [7] xtable_1.8-2      git2r_0.13.1      httr_1.1.0       
[10] curl_0.9.5        miniUI_0.1.1      rmarkdown_0.9.5.8
[13] tools_3.2.3       shiny_0.13.2      httpuv_1.3.3     
[16] yaml_2.1.13       rsconnect_0.4.2.2 memoise_1.0.0    
[19] htmltools_0.3.5
yihui commented 8 years ago

I cannot reproduce this issue on Windows. Can you print out the version of XeTeX?

system('xelatex --version')
melindahiggins2000 commented 8 years ago

Here is my xelatex version:

> system('xelatex --version')
MiKTeX-XeTeX 2.9.5840 (0.99992) (MiKTeX 2.9)
(C) 1994-2008 by SIL International, (C) 2009-2012 by Jonathan Kew, (C) 2010-2012 by Han Han The Thanh, (C) 2012-2013 by Khaled Hosny
TeX is a trademark of the American Mathematical Society.
compiled with zlib version 1.2.8; using 1.2.8
compiled with libpng version 1.6.19; using 1.6.19
compiled with poppler version 0.32.0
compiled with jpeg version 8.4
compiled with fontconfig version 2.11.94; using 2.11.94
compiled with FreeType2 version 2.5.5; using 2.5.5
compiled with Graphite2 version 1.2.4; using 1.2.4
compiled with ICU version 55.1; using 55.1
compiled with HarfBuzz version 0.9.40; using 0.9.40
using TECkit version 2.4
yihui commented 8 years ago

I cannot think of a possible reason why it could fail to find the figure file. Can you delete the _book directory and try to compile the example to PDF again?

melindahiggins2000 commented 8 years ago

Yihui - thank you. I did remove the _book directory and am still getting errors. I'll try updating my MiKTeX later today to see if that fixes the issues. I ran the "bookdown-demo.tex" file through "TeXworks" (v.0.4.6/MiKTeX 2.9) [r.c29723a] and get the errors noted in the log file below.

In digging through the LOG file, I'm getting what looks like cross-ref errors. For Chapter 2 - I get the following errors. Note: I changed the figure label from nice-fig to niceFig.

Chapter 2.

LaTeX Warning: Reference `intro' on page 7 undefined on input line 158.

LaTeX Warning: Reference `methods' on page 7 undefined on input line 160.

LaTeX Font Info:    Try loading font information for TS1+lmtt on input line 168
.
("C:\Program Files (x86)\MiKTeX 2.9\tex\latex\lm\ts1lmtt.fd"
File: ts1lmtt.fd 2009/10/30 v1.6 Font defs for Latin Modern
)

! LaTeX Error: File `bookdown-demo_files/figure-latex/niceFig-1' not found.

Thank you for the help! Melinda

yihui commented 8 years ago

Can you add keep_tex: yes to _output.yml and retry? i.e.

bookdown::pdf_book:
  includes:
    in_header: preamble.tex
  latex_engine: xelatex
  citation_package: natbib
  keep_tex: yes

See if _book/bookdown-demo_files/figure-latex/niceFig-1.png exists?

melindahiggins2000 commented 8 years ago

I deleted everything I had before and re-downloaded the Github zipped repository to my local drive (bookdown-demo) to start again fresh.

I then added keep_tex: yes to _output.yml and ran "Build Book" and choose bookdown::pdf_book.

When I check my files there is a figure "nice-fig-1.pdf" located in a slightly different directory "..._book_bookdown_files\bookdown-demo_files\figure-latex"

maybe there is a directory setting that is off?

Note: Building the book to bookdown::gitbook and bookdown::epub_book both seem to be working fine. Just bookdown::pdf_book issues.

melindahiggins2000 commented 8 years ago

oops - sorry the directory is

. . . /_book/_bookdown_files/bookdown-demo_files/figure-latex/nice-fig-1.pdf

yihui commented 8 years ago

Scratching my head for a while and still have no idea how this could possibly happen. Are you available some time tomorrow for a short chat with screensharing?

When you build the book to PDF, do you see a directory bookdown-demo_files appear in the Files panel of RStudio? It only shows up there temporarily and will be moved away later. I have recorded a video to show what is expected to happen: https://dl.dropboxusercontent.com/u/15335397/misc/bookdown-demo.mp4

melindahiggins2000 commented 8 years ago

I might be able to do a online/chat meeting late tomorrow afternoon (4:00 pm EST). However, in the meantime, thank you very much for your video! I also did a quick video capture of what happens when I open the "bookdown-demo.Rproj", then open the "_output.yml" file and add the keep_tex: yes option and then Build the Book using bookdown::pdf_book. I also captured the directory changes so you could see them as they build on my computer. The latex figure does get created but in a slightly different directory & I'm still getting LaTeX "internal errors." See my video of my process and resulting errors at https://youtu.be/MlXuhC4GDjc I suspect it may be user error on my part - maybe I do not have MiKTeX configured correctly or perhaps I should be using a different LaTeX engine in Windows. I'll admit, I'm a bit of a newbie when it comes to LaTeX which is why I love Rmarkdown so much!

yihui commented 8 years ago

Can you move the bookdown-demo_files directory back to the root directory, and try to compile bookdown-demo.tex with xelatex?

melindahiggins2000 commented 8 years ago

Yihui, Thank you. That worked. Is there a directory setting I should update somewhere; or I'll just make a note of this issue and look for updates in the future?

By the way - AWESOME job on bookdown! I've been playing with Gitbook and the rgitbook package for awhile now and having very good success testing this out in workshops and classes. I'll definitely be testing bookdown more in the future. I love being able to compile and disseminate teaching materials, reports and research using these formats and the flexibility to move between online, mobile and hardcopy options.

Also, just curious - any future development planned for being able to support the rmarkdown::word_document() options? The majority of my collaborators and students need/want to work in MS Word and related office software products.

Thank you again for all the time and great feedback! Melinda Higgins

yihui commented 8 years ago

I guess we still have not solved the original issue. The Build Book button still does not work, right? You should not need to open .tex and compile it manually every time. I don't know what went wrong there.

Re: word documents, if you only want to combine multiple Rmd's and generate them into one Word document, that is easy. For other features like figure/table caption numbering / cross-references, I'm afraid they will be tricky to implement.

melindahiggins2000 commented 8 years ago

Yihui, I'll try to run a trace and walk though the specifics on my system and see if I can isolate the directory issue. In the meantime, the workaround is fine. I'll also test out using the KM (knit-then-merge) approach and play around with MS word formats. If I can get 90+% of the document done and exported to Word fixing the cross references later is fine.

Thank you again very much for all the time and insights. If I sort out the issue, I'll add a post in the future. In the meantime, you have my notes in case this shows up for another bookdown user/beta-tester.

:-) Melinda

mikebirdgeneau commented 8 years ago

I'm running into the same issue:

! LaTeX Error: File `bookdown-demo_files/figure-latex/nice-fig-1' not found.

If I run:

bookdown::render_book("index.Rmd", "bookdown::pdf_book",clean=FALSE)

Then I see nice-fig-1.pdf show-up in the figure-latex directory, but for some reason, when compiling the LaTeX file, it can't find this -- is this something to do with the file extension?

The other note that shows-up in my console is:

Error: Failed to compile bookdown-demo.tex. See bookdown-demo.log for more info.
In addition: Warning messages:
1: In FUN(...) :
  Perl must be installed and put on PATH for latexmk to work
2: running command '"pdflatex" -halt-on-error -interaction=batchmode "bookdown-demo.tex"' had status 1 
> 

Moving the *.tex file into the _bookdown_files folder and compiling works.

Windows 7 x64
bookdown 0.0.74
R 3.2.4 (2016-03-10)
MiKTeX-XeTeX 2.9.4987 (0.9999.3) (MiKTeX 2.9)
yihui commented 8 years ago

Could you run the code below and show me the output?

aux_diro = "_bookdown_files"
aux_dirs = bookdown:::files_cache_dirs(aux_diro)
print(aux_dirs)
file.rename(aux_dirs, basename(aux_dirs))

aux_dirs = bookdown:::files_cache_dirs(".")
print(aux_dirs)
bookdown:::dir_create(aux_diro)
file.rename(aux_dirs, file.path(aux_diro, basename(aux_dirs)))

The output should look like this:

> aux_diro = "_bookdown_files"
> aux_dirs = bookdown:::files_cache_dirs(aux_diro)
> print(aux_dirs)
[1] "_bookdown_files/bookdown-demo_files"
> file.rename(aux_dirs, basename(aux_dirs))
[1] TRUE
> 
> aux_dirs = bookdown:::files_cache_dirs(".")
> print(aux_dirs)
[1] "./bookdown-demo_files"
> bookdown:::dir_create(aux_diro)
[1] TRUE
> file.rename(aux_dirs, file.path(aux_diro, basename(aux_dirs)))
[1] TRUE
melindahiggins2000 commented 8 years ago

Yihui, Thank you for still trying to fix this issue. I just got back from vacation.

I downloaded a clean ZIP'd copy of the bookdown-demo-master from this repository. When I opened the Rproj in a clean R session, the Build interface looked different - it said "Build and Reload" - upon inspection I realized the BuildType was set to Package. I changed this to Website and was able to get the Build Book options back.

I ran the bookdown::gitbook and bookdown::epub_book "Build Book" options. Both of these worked fine. When I ran bookdown::pdf_book "Build Book", I get the following errors:

"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS bookdown-demo.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output bookdown-demo.tex --table-of-contents --toc-depth 2 --template "C:\Users\MKHIGGI\Documents\R\win-library\3.3\rmarkdown\rmd\latex\default-1.17.0.2.tex" --number-sections --highlight-style tango --latex-engine xelatex --natbib --include-in-header preamble.tex --variable graphics=yes --variable "geometry:margin=1in" --bibliography book --bibliography packages 
output file: bookdown-demo.knit.md

latexmk.exe: MiKTeX encountered an internal error.
Error: Failed to compile bookdown-demo.tex.
In addition: Warning messages:
1: running command '"C:\PROGRA~1\MIKTEX~1.9\miktex\bin\x64\latexmk.exe" -pdf -latexoption=-halt-on-error -interaction=batchmode -pdflatex="xelatex" "bookdown-demo.tex"' had status 1 
2: running command '"C:\PROGRA~1\MIKTEX~1.9\miktex\bin\x64\latexmk.exe" -v' had status 1 
Execution halted

Exited with status 1.

I also ran the commands you listed above, here is my output.

> aux_diro = "_bookdown_files"
> aux_dirs = bookdown:::files_cache_dirs(aux_diro)
> print(aux_dirs)
character(0)
> file.rename(aux_dirs, basename(aux_dirs))
logical(0)
> aux_dirs = bookdown:::files_cache_dirs(".")
> print(aux_dirs)
character(0)
> bookdown:::dir_create(aux_diro)
[1] TRUE
> file.rename(aux_dirs, file.path(aux_diro, basename(aux_dirs)))
logical(0)

Note: after running through all of the above, here is my directory contents:

C:\MyR\bookdown_demo_build\bookdown-demo-master>tree
Folder PATH listing
Volume serial number is AC7D-A6A5
C:.
├───_book
│   ├───bookdown-demo_files
│   │   └───figure-html
│   └───libs
│       ├───gitbook-2.6.7
│       │   ├───css
│       │   │   └───fontawesome
│       │   └───js
│       └───jquery-2.2.3
└───_bookdown_files

and there are no files in the _bookdown_files directory:

C:\MyR\bookdown_demo_build\bookdown-demo-master\_bookdown_files>dir
 Volume in drive C has no label.
 Volume Serial Number is AC7D-A6A5

 Directory of C:\MyR\bookdown_demo_build\bookdown-demo-master\_bookdown_files

07/11/2016  09:34 AM    <DIR>          .
07/11/2016  09:34 AM    <DIR>          ..
               0 File(s)              0 bytes
               2 Dir(s)  86,342,656,000 bytes free

Thank you again for your time and assistance!

melindahiggins2000 commented 8 years ago

Note: I also opened the bookdown-demo.tex file in TeXworks and "compiled" the TEX document. Here are the error messages I get. It looks like the references are undefined and it cannot find the figure given the path it is expecting. There is also no _bookdown-demo_files directory - it was not created in the root directory. There is one in the _book directory - see tree directory listing in above post.

I opened the bookdown-demo.tex file in TeXWorks and compiled it there - here are the errors:
============================================================
This is pdfTeX, Version 3.14159265-2.6-1.40.16 (MiKTeX 2.9 64-bit)
entering extended mode
(C:/MyR/bookdown_demo_build/bookdown-demo-master/bookdown-demo.tex
LaTeX2e <2016/03/31>
Babel <3.9q> and hyphenation patterns for 70 language(s) loaded.
("C:\Program Files\MiKTeX 2.9\tex\latex\base\book.cls"
Document Class: book 2014/09/29 v1.4h Standard LaTeX document class
("C:\Program Files\MiKTeX 2.9\tex\latex\base\bk10.clo"))
("C:\Program Files\MiKTeX 2.9\tex\latex\lm\lmodern.sty")
("C:\Program Files\MiKTeX 2.9\tex\latex\amsfonts\amssymb.sty"
("C:\Program Files\MiKTeX 2.9\tex\latex\amsfonts\amsfonts.sty"))
("C:\Program Files\MiKTeX 2.9\tex\latex\amsmath\amsmath.sty"
For additional information on amsmath, use the `?' option.
("C:\Program Files\MiKTeX 2.9\tex\latex\amsmath\amstext.sty"
("C:\Program Files\MiKTeX 2.9\tex\latex\amsmath\amsgen.sty"))
("C:\Program Files\MiKTeX 2.9\tex\latex\amsmath\amsbsy.sty")
("C:\Program Files\MiKTeX 2.9\tex\latex\amsmath\amsopn.sty"))
("C:\Program Files\MiKTeX 2.9\tex\generic\ifxetex\ifxetex.sty")
("C:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\ifluatex.sty")
("C:\Program Files\MiKTeX 2.9\tex\latex\base\fixltx2e.sty"

Package fixltx2e Warning: fixltx2e is not required with releases after 2015
(fixltx2e)                All fixes are now in the LaTeX kernel.
(fixltx2e)                See the latexrelease package for details.

) ("C:\Program Files\MiKTeX 2.9\tex\latex\base\fontenc.sty"
("C:\Program Files\MiKTeX 2.9\tex\latex\base\t1enc.def"))
("C:\Program Files\MiKTeX 2.9\tex\latex\base\inputenc.sty"
("C:\Program Files\MiKTeX 2.9\tex\latex\base\utf8.def"
("C:\Program Files\MiKTeX 2.9\tex\latex\base\t1enc.dfu")
("C:\Program Files\MiKTeX 2.9\tex\latex\base\ot1enc.dfu")
("C:\Program Files\MiKTeX 2.9\tex\latex\base\omsenc.dfu")))
("C:\Program Files\MiKTeX 2.9\tex\latex\upquote\upquote.sty"
("C:\Program Files\MiKTeX 2.9\tex\latex\base\textcomp.sty"
("C:\Program Files\MiKTeX 2.9\tex\latex\base\ts1enc.def"
("C:\Program Files\MiKTeX 2.9\tex\latex\base\ts1enc.dfu"))))
("C:\Program Files\MiKTeX 2.9\tex\latex\microtype\microtype.sty"
("C:\Program Files\MiKTeX 2.9\tex\latex\graphics\keyval.sty")
("C:\Program Files\MiKTeX 2.9\tex\latex\microtype\microtype-pdftex.def")
("C:\Program Files\MiKTeX 2.9\tex\latex\microtype\microtype.cfg"))
("C:\Program Files\MiKTeX 2.9\tex\latex\geometry\geometry.sty"
("C:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\ifpdf.sty")
("C:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\ifvtex.sty")
("C:\Program Files\MiKTeX 2.9\tex\latex\geometry\geometry.cfg"))
("C:\Program Files\MiKTeX 2.9\tex\latex\hyperref\hyperref.sty"
("C:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\hobsub-hyperref.sty"
("C:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\hobsub-generic.sty"))
("C:\Program Files\MiKTeX 2.9\tex\latex\oberdiek\auxhook.sty")
("C:\Program Files\MiKTeX 2.9\tex\latex\oberdiek\kvoptions.sty")
("C:\Program Files\MiKTeX 2.9\tex\latex\hyperref\pd1enc.def")
("C:\Program Files\MiKTeX 2.9\tex\latex\00miktex\hyperref.cfg")
("C:\Program Files\MiKTeX 2.9\tex\latex\url\url.sty"))

Package hyperref Message: Driver (autodetected): hpdftex.

("C:\Program Files\MiKTeX 2.9\tex\latex\hyperref\hpdftex.def"
("C:\Program Files\MiKTeX 2.9\tex\latex\oberdiek\rerunfilecheck.sty"))
("C:\Program Files\MiKTeX 2.9\tex\latex\hyperref\puenc.def")
("C:\Program Files\MiKTeX 2.9\tex\latex\natbib\natbib.sty")
("C:\Program Files\MiKTeX 2.9\tex\latex\graphics\color.sty"
("C:\Program Files\MiKTeX 2.9\tex\latex\00miktex\color.cfg")
("C:\Program Files\MiKTeX 2.9\tex\latex\pdftex-def\pdftex.def"))
("C:\Program Files\MiKTeX 2.9\tex\latex\fancyvrb\fancyvrb.sty"
Style option: `fancyvrb' v2.7a, with DG/SPQR fixes, and firstline=lastline fix 
<2008/02/07> (tvz)) ("C:\Program Files\MiKTeX 2.9\tex\latex\framed\framed.sty")
 ("C:\Program Files\MiKTeX 2.9\tex\latex\graphics\graphicx.sty"
("C:\Program Files\MiKTeX 2.9\tex\latex\graphics\graphics.sty"
("C:\Program Files\MiKTeX 2.9\tex\latex\graphics\trig.sty")
("C:\Program Files\MiKTeX 2.9\tex\latex\00miktex\graphics.cfg")))
("C:\Program Files\MiKTeX 2.9\tex\latex\oberdiek\grffile.sty")
("C:\Program Files\MiKTeX 2.9\tex\latex\ltxmisc\parskip.sty")
("C:\Program Files\MiKTeX 2.9\tex\latex\booktabs\booktabs.sty")
("C:\Program Files\MiKTeX 2.9\tex\latex\titling\titling.sty")
No file bookdown-demo.aux.
("C:\Program Files\MiKTeX 2.9\tex\latex\base\ts1cmr.fd")
("C:\Program Files\MiKTeX 2.9\tex\latex\lm\t1lmr.fd")
("C:\Program Files\MiKTeX 2.9\tex\latex\microtype\mt-cmr.cfg")
*geometry* driver: auto-detecting
*geometry* detected driver: pdftex
("C:\Program Files\MiKTeX 2.9\tex\latex\hyperref\nameref.sty"
("C:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\gettitlestring.sty"))
("C:\Program Files\MiKTeX 2.9\tex\context\base\supp-pdf.mkii"
[Loading MPS to PDF converter (version 2006.09.02).]
) ("C:\Program Files\MiKTeX 2.9\tex\latex\oberdiek\epstopdf-base.sty"
("C:\Program Files\MiKTeX 2.9\tex\latex\oberdiek\grfext.sty")) [1{C:/Users/MKHI
GGI/AppData/Local/MiKTeX/2.9/pdftex/config/pdftex.map}] [2] [3] [4]
Chapter 1.
("C:\Program Files\MiKTeX 2.9\tex\latex\lm\ot1lmr.fd")
("C:\Program Files\MiKTeX 2.9\tex\latex\lm\omllmm.fd")
("C:\Program Files\MiKTeX 2.9\tex\latex\lm\omslmsy.fd")
("C:\Program Files\MiKTeX 2.9\tex\latex\lm\omxlmex.fd")
("C:\Program Files\MiKTeX 2.9\tex\latex\amsfonts\umsa.fd")
("C:\Program Files\MiKTeX 2.9\tex\latex\microtype\mt-msa.cfg")
("C:\Program Files\MiKTeX 2.9\tex\latex\amsfonts\umsb.fd")
("C:\Program Files\MiKTeX 2.9\tex\latex\microtype\mt-msb.cfg")
("C:\Program Files\MiKTeX 2.9\tex\latex\lm\t1lmtt.fd") [5] [6]
Chapter 2.

LaTeX Warning: Reference `intro' on page 7 undefined on input line 159.

LaTeX Warning: Reference `methods' on page 7 undefined on input line 161.

("C:\Program Files\MiKTeX 2.9\tex\latex\lm\ts1lmtt.fd")

! LaTeX Error: File `bookdown-demo_files/figure-latex/nice-fig-1' not found.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.175 ...kdown-demo_files/figure-latex/nice-fig-1}

? 
melindahiggins2000 commented 8 years ago

Note: here is the relevant section of the bookdown-demo.tex file that throws the errors for the 'intro' and 'methods' references not found as well as the 'nice-fig-1' not found error.

\chapter{Introduction}\label{intro}

You can label chapter and section titles using \texttt{\{\#label\}}
after them, e.g., we can reference Chapter \ref{intro}. If you do not
manually label them, there will be automatic labels anyway, e.g.,
Chapter \ref{methods}.

Figures and tables with captions will be placed in \texttt{figure} and
\texttt{table} environments, respectively.

\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{par}\NormalTok{(}\DataTypeTok{mar =} \KeywordTok{c}\NormalTok{(}\DecValTok{4}\NormalTok{, }\DecValTok{4}\NormalTok{, .}\DecValTok{1}\NormalTok{, .}\DecValTok{1}\NormalTok{))}
\KeywordTok{plot}\NormalTok{(pressure, }\DataTypeTok{type =} \StringTok{'b'}\NormalTok{, }\DataTypeTok{pch =} \DecValTok{19}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{figure}

{\centering \includegraphics[width=0.8\linewidth]{bookdown-demo_files/figure-latex/nice-fig-1} 

}

\caption{Here is a nice figure!}\label{fig:nice-fig}
\end{figure}
yihui commented 8 years ago

Okay, I guess there are two issues here. Can you first run shell('latexmk -v')? I'll think about the second possible issue. And also make sure you have the latest version of bookdown: devtools::install_github('rstudio/bookdown')

melindahiggins2000 commented 8 years ago

Here is the output from `shell('latexmk -v')

> shell('latexmk -v')

Latexmk, John Collins, 24 February 2016. Version 4.44

I'll download the latest version of bookdown and try again... I'll send an update shortly...

yihui commented 8 years ago

How about system2('latexmk', '-v')?

melindahiggins2000 commented 8 years ago

That returned an error...

> system2('latexmk', '-v')
latexmk.exe: MiKTeX encountered an internal error.
Warning message:
running command '"latexmk" -v' had status 1 
yihui commented 8 years ago

Okay, that is one issue I need to figure out. For now, could you test this?

devtools::install_github('yihui/rmarkdown@bugfix/windows-install-latexmk')

Note you may need to restart your R session.

melindahiggins2000 commented 8 years ago

I had to first install the mime package and then the current version of bookdown would install.

I also ran devtools::install_github('yihui/rmarkdown@bugfix/windows-install-latexmk') and it loaded ok.

I then ran "Build Book" using bookdown::pdf_book and the bookdown-demo_files directory was created, but then after about 20 sec, the PDF preview window opened and the directory went away. But the PDF bookdown-demo.pdf was created in the _book directory and the references and figure look good.

Is there a 'bug fix' I need to apply for my LaTeX installation or is this a patch for the rmarkdown package? (just curious).

But this appears to have worked.

yihui commented 8 years ago

bookdown-demo_files will be moved to _bookdown_files after the PDF is created, so what you observed is normal.

Okay, the original problem seems to be due to system2() not being able to execute latexmk. I don't think there is anything to fix on your side. I can probably provide another fix in rmarkdown, but since you are able to create the PDF now, it may not be of high priority.

melindahiggins2000 commented 8 years ago

Sounds good. I'll stay tuned for updates to rmarkdown. I have had good luck running system() commands but often get errors with system2() commands.

For example:

> system('jekyll -v')
jekyll 3.1.6
> system2('jekyll -v')
Warning message:
running command '"jekyll -v"' had status 127 
yihui commented 8 years ago

Actually you should run system2('jekyll', '-v'). Does that work?

mikebirdgeneau commented 8 years ago

I'm following the progress you guys are making.

I've run: devtools::install_github('yihui/rmarkdown@bugfix/windows-install-latexmk') Which ran successfully.

When I run system2('latexmk', '-v') I get:

latexmk.exe: The Perl interpreter could not be found.
Warning message:
running command '"latexmk" -v' had status 1 

Looks like I have a slightly different underlying issue.

yihui commented 8 years ago

@mikebirdgeneau Yes, yours is different -- it seems you didn't install Perl. That is actually fine. rmarkdown will just use a fallback method to compile LaTeX. To be clear, are you able to get the PDF now?

melindahiggins2000 commented 8 years ago

yes, that worked:

> system2('jekyll', '-v')
jekyll 3.1.6

but the latexmk command still gives me an error.

> system2('latexmk', '-v')
latexmk.exe: MiKTeX encountered an internal error.
Warning message:
running command '"latexmk" -v' had status 1 
melindahiggins2000 commented 8 years ago

I missed the slight syntax difference between system() and system2() - thank you.

Yes, with the devtools::install_github('yihui/rmarkdown@bugfix/windows-install-latexmk') I am able to produce the PDF file.

yihui commented 8 years ago

@melindahiggins2000 latexmk seems to be a different animal that I don't understand. Anyway, I think you can just ignore this latexmk issue as long as the patched version of rmarkdown gives you the PDF.

melindahiggins2000 commented 8 years ago

No problem. It is a weird issue.

From the RStudio Console if I type:

> system('latexmk -v')
latexmk.exe: MiKTeX encountered an internal error.
Warning message:
running command 'latexmk -v' had status 1 

I get an error. But from my Windows Command window - it works fine.

C:\MyR\bookdown_demo_build\bookdown-demo-master>latexmk -v

Latexmk, John Collins, 24 February 2016. Version 4.44

Oh well. I'll use the rmarkdown workaround for how. Thank you!

yihui commented 8 years ago

Yeah I feel latexmk needs a shell to be executed on Windows. That is quite unusual.

melindahiggins2000 commented 8 years ago

I get a similar error if I try to get my path listing from the RStudio Console window

> system('path')
Warning message:
running command 'path' had status 127

but the path command works fine from the Windows Command line.

What is even weirder is that the jekyll -v command works fine from either the RStudio console window:

> system('jekyll -v')
jekyll 3.1.6

or in the Windows console:

C:\MyR\bookdown_demo_build\bookdown-demo-master>jekyll -v
jekyll 3.1.6

maybe something going on with system() commands? I tried these using shell() and they worked...

FYI - the shell() commands - from my RStudio Console:

> shell('jekyll -v')
jekyll 3.1.6
> shell('latexmk -v')

Latexmk, John Collins, 24 February 2016. Version 4.44
> shell('path')
PATH=C:\Program Files\R\R-3.3.0\bin\x64;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\MATLAB\R2015b\runtime\win64;C:\Program Files\MATLAB\R2015b\bin;C:\Program Files\nodejs\;C:\Program Files (x86)\Skype\Phone\;C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;C:\Program Files\MiKTeX 2.9\miktex\bin\x64\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Calibre2\;C:\Program Files (x86)\Pandoc\;C:\Ruby22-x64\bin;C:\Users\MKHIGGI\AppData\Roaming\npm
> 
melindahiggins2000 commented 8 years ago

what is the difference between shell() and system()?

yihui commented 8 years ago

As its name indicated, shell() uses a shell to execute the command (e.g. cmd.exe), and system2() executes the command directly.

melindahiggins2000 commented 8 years ago

Thank you for the clarification and all your time and effort tracking down these issues!

mikebirdgeneau commented 8 years ago

@yihui I'm not able to compile the PDF still (on Windows at least):

Output of:

bookdown::render_book("index.Rmd", "bookdown::pdf_book")

is:

Latexmk, John Collins, 22 April 2016. Version 4.45
Error: Failed to compile bookdown-demo.tex.
In addition: Warning messages:
1: running command '"C:\PROGRA~2\MIKTEX~1.9\miktex\bin\latexmk.exe" -v' had status 1 
2: The LaTeX package latexmk was not correctly installed. 
3: running command '"C:\PROGRA~2\MIKTEX~1.9\miktex\bin\latexmk.exe" -v' had status 1 
4: In FUN(...) :
  Perl must be installed and put on PATH for latexmk to work
5: running command '"xelatex" -halt-on-error -interaction=batchmode "bookdown-demo.tex"' had status

It all works great on OSX / Linux.

yihui commented 8 years ago

@mikebirdgeneau Could you run the code below and show its output?

list.files()

aux_diro = "_bookdown_files"
aux_dirs = bookdown:::files_cache_dirs(aux_diro)
print(aux_dirs)
file.rename(aux_dirs, basename(aux_dirs))

aux_dirs = bookdown:::files_cache_dirs(".")
print(aux_dirs)
bookdown:::dir_create(aux_diro)
file.rename(aux_dirs, file.path(aux_diro, basename(aux_dirs)))

library(rmarkdown)
devtools::session_info()
mikebirdgeneau commented 8 years ago
> list.files()
 [1] "_book"               "_bookdown.yml"       "_bookdown_files"     "_output.yml"         "01-intro.Rmd"       
 [6] "02-literature.Rmd"   "03-method.Rmd"       "04-application.Rmd"  "05-summary.Rmd"      "06-references.Rmd"  
[11] "book.bib"            "bookdown-demo.log"   "bookdown-demo.Rproj" "bookdown-demo.tex"   "index.Rmd"          
[16] "LICENSE"             "packages.bib"        "preamble.tex"        "prerequisites.html"  "README.md"          
[21] "style.css"           "toc.css"            
> aux_diro = "_bookdown_files"
> aux_dirs = bookdown:::files_cache_dirs(aux_diro)
> print(aux_dirs)
character(0)
> file.rename(aux_dirs, basename(aux_dirs))
logical(0)
> aux_dirs = bookdown:::files_cache_dirs(".")
> print(aux_dirs)
character(0)
> bookdown:::dir_create(aux_diro)
[1] TRUE
> file.rename(aux_dirs, file.path(aux_diro, basename(aux_dirs)))
logical(0)
> library(rmarkdown)
> devtools::session_info()
Session info --------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.2.4 (2016-03-10)
 system   x86_64, mingw32             
 ui       RStudio (0.99.484)          
 language (EN)                        
 collate  English_United States.1252  
 tz       America/Denver              
 date     2016-07-11                  

Packages ------------------------------------------------------------------------------------------------------------
 package   * version date       source                           
 bookdown    0.0.79  2016-07-11 Github (rstudio/bookdown@8fd8a8c)
 devtools    1.12.0  2016-06-24 CRAN (R 3.2.5)                   
 digest      0.6.9   2016-01-08 CRAN (R 3.2.3)                   
 evaluate    0.9     2016-04-29 CRAN (R 3.2.5)                   
 formatR     1.4     2016-05-09 CRAN (R 3.2.5)                   
 highr       0.6     2016-05-09 CRAN (R 3.2.5)                   
 htmltools   0.3.5   2016-03-21 CRAN (R 3.2.5)                   
 httpuv      1.3.3   2015-08-04 CRAN (R 3.2.4)                   
 knitr       1.13.2  2016-07-11 Github (yihui/knitr@40d825e)     
 magrittr    1.5     2014-11-22 CRAN (R 3.2.4)                   
 memoise     1.0.0   2016-01-29 CRAN (R 3.2.4)                   
 mime        0.4     2015-09-03 CRAN (R 3.2.3)                   
 miniUI      0.1.1   2016-01-15 CRAN (R 3.2.3)                   
 R6          2.1.2   2016-01-26 CRAN (R 3.2.4)                   
 Rcpp        0.12.5  2016-05-14 CRAN (R 3.2.5)                   
 rmarkdown * 1.0     2016-07-11 Github (yihui/rmarkdown@ce3f4a8) 
 shiny       0.13.2  2016-03-28 CRAN (R 3.2.5)                   
 stringi     1.1.1   2016-05-27 CRAN (R 3.2.5)                   
 stringr     1.0.0   2015-04-30 CRAN (R 3.2.4)                   
 withr       1.0.2   2016-06-20 CRAN (R 3.2.5)                   
 xtable      1.8-2   2016-02-05 CRAN (R 3.2.4)                   
 yaml        2.1.13  2014-06-12 CRAN (R 3.2.4)                   
mikebirdgeneau commented 8 years ago

It looks like my call to print(aux_dirs) isn't returning [1] "./bookdown-demo_files"

Could it be related to my RStudio version? ui RStudio (0.99.484)

melindahiggins2000 commented 8 years ago

@mikebirdgeneau I also get a similar result where print(aux_dirs) returns character(0). I'm running Windows10 OS.

yihui commented 8 years ago

@mikebirdgeneau I don't think the RStudio version is relevant, but you may try to upgrade anyway: https://www.rstudio.com/products/rstudio/download/preview/

Are there any directories under _bookdown_files?

mikebirdgeneau commented 8 years ago

I'll try upgrading as soon as some stuff I have running finishes. There are no files in that directory it's all empty.

> list.files(path = "_bookdown_files")
character(0)
mikebirdgeneau commented 8 years ago

I added keep_tex: true back into my _output.yml file, and got this:

output file: bookdown-demo.knit.md

"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS bookdown-demo.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output bookdown-demo.tex --table-of-contents --toc-depth 2 --template "U:\R\win-library\3.2\rmarkdown\rmd\latex\default.tex" --number-sections --highlight-style tango --latex-engine xelatex --natbib --include-in-header preamble.tex --variable graphics=yes --variable "geometry:margin=1in" --variable tables=yes --standalone --bibliography book --bibliography packages 

Latexmk, John Collins, 22 April 2016. Version 4.45
! LaTeX Error: File `pdftex.def' not found.

! Emergency stop.
<read *> 

Error: Failed to compile bookdown-demo.tex. See bookdown-demo.log for more info.
In addition: Warning messages:
1: running command '"C:\PROGRA~2\MIKTEX~1.9\miktex\bin\latexmk.exe" -v' had status 1 
2: The LaTeX package latexmk was not correctly installed. 
3: running command '"C:\PROGRA~2\MIKTEX~1.9\miktex\bin\latexmk.exe" -v' had status 1 
4: In FUN(...) :
  Perl must be installed and put on PATH for latexmk to work
5: running command '"xelatex" -halt-on-error -interaction=batchmode "bookdown-demo.tex"' had status 1 
> 

And then:

> list.files(path = "_bookdown_files",recursive = TRUE)
[1] "bookdown-demo_files/figure-latex/nice-fig-1.pdf"
mikebirdgeneau commented 8 years ago

I'm going to see if I'm missing pdftex-def from my LaTeX install.

melindahiggins2000 commented 8 years ago

I haven't had a chance to check this out - but I'm wondering if there is a disconnect between my Perl installation and the latexmk package in my MiKTeX installation. I have "Strawberry Perl" installed which places the perl.exe in this directory C:\Strawberry\perl\bin

According to this 2010 post, latexmk expects to find perl.exe in the C:\perl\bin directory. see post at http://www.latex-community.org/forum/viewtopic.php?f=5&t=12566.

I'll check this out tomorrow. I may see if there is a custom option for setting the default directories when Strawberry Perl is installed and/or may try installing ActiveState Perl instead - see https://www.perl.org/get.html#win32

Let me know if you (@mikebirdgeneau) try this and it works...

yihui commented 8 years ago

@melindahiggins2000 I don't think the location of perl.exe matters. I installed ActiveState Perl on Windows, and it works fine for me. It must be a different issue in @mikebirdgeneau's case.

melindahiggins2000 commented 8 years ago

@yihui you are correct. Moving my Perl installation directory had no effect. When I "Build Book" with bookdown::pdf_book I now get the PDF file (thank you), but still get a few LaTeX error messages at the end (see below). But other than it being a nagging issue I haven't solved yet, everything is working ok. Thank you!

Remaining error messages at the end of the "Build Book" to PDF log - something with latexmk and perl.

output file: bookdown-demo.knit.md

Latexmk, John Collins, 24 February 2016. Version 4.44

Output created: _book/bookdown-demo.pdf
Warning messages:
1: running command '"C:\PROGRA~1\MIKTEX~1.9\miktex\bin\x64\latexmk.exe" -v' had status 1 
2: The LaTeX package latexmk was not correctly installed. 
3: running command '"C:\PROGRA~1\MIKTEX~1.9\miktex\bin\x64\latexmk.exe" -v' had status 1 
4: In FUN(...) :
  Perl must be installed and put on PATH for latexmk to work