ulyngs / oxforddown

Template for writing an Oxford University thesis in R Markdown; uses the OxThesis LaTeX template and was inspired by thesisdown.
https://ulyngs.github.io/oxforddown/
MIT License
221 stars 81 forks source link

make word fails on Ubuntu #10

Closed paulsharpeY closed 3 years ago

paulsharpeY commented 3 years ago
$ uname -a
Linux 4.15.0-112-generic #113-Ubuntu SMP Thu Jul 9 23:41:39 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
$ make clean && make word
rm -f *.log *.mtc* *.maf *.aux *.bbl *.blg *.xml
Rscript -e 'options(bookdown.render.file_scope = FALSE); bookdown::render_book("index.Rmd", output_format = "bookdown::word_document2")'

processing file: _main.Rmd

...

output file: _main.knit.md

UTF-8 decoding error in _main.utf8.md at byte offset 33057 (f8).
The input must be a UTF-8 encoded text.
Error: pandoc document conversion failed with error 92
In addition: Warning messages:
1: In read_utf8(file) :
  The file pandoc5f3663777eed is not encoded in UTF-8. These lines contain invalid UTF-8 characters: 3, 4, 5, 6, 7, 8, ...
2: In hook(x[i], reduce_plot_opts(options)) :
  Chunk options fig.align is not supported for docx output
3: In hook(x[i], reduce_plot_opts(options)) :
  Chunk options fig.align is not supported for docx output
4: In hook(x[i], reduce_plot_opts(options)) :
  Chunk options fig.align is not supported for docx output
5: In hook(x[i], reduce_plot_opts(options)) :
  Chunk options fig.align is not supported for docx output
6: In read_utf8(file) :
  The file pandoc5f36489bcc80 is not encoded in UTF-8. These lines contain invalid UTF-8 characters: 3, 4, 5, 6, 7, 8, ...
7: In read_utf8(file) :
  The file pandoc5f36364cfd3 is not encoded in UTF-8. These lines contain invalid UTF-8 characters: 3, 4, 5, 6, 7, 8, ...
8: In read_utf8(file) :
  The file pandoc5f36740b5691 is not encoded in UTF-8. These lines contain invalid UTF-8 characters: 3, 4, 5, 6, 7, 8, ...
9: In readLines(con, warn = FALSE) :
  invalid input found on input connection '_main.knit.md'
Execution halted
Warning message:
In file.remove(intermediate_html) :
  cannot remove file '_main.utf8.tmp.html', reason 'No such file or directory'
Makefile:11: recipe for target 'word' failed
make: *** [word] Error 1
paulsharpeY commented 3 years ago

Knitting some individual chapters to word_document2 works.

paulsharpeY commented 3 years ago

I narrowed this down to an issue with correction blocks. You should be able to reproduce this by knitting chapter 3 (works) and chapter 4 (fails) to Word. I reproduced this in a document with a single correction block, so I think inline corrections are fine. Here's the error when building chapter 4.

output file: 04-oxthesis.knit.md

UTF-8 decoding error in 04-oxthesis.utf8.md at byte offset 2271 (f8).
The input must be a UTF-8 encoded text.
Error: pandoc document conversion failed with error 92
In addition: Warning messages:
1: In read_utf8(file) :
  The file pandoc4e7e458b9109 is not encoded in UTF-8. These lines contain invalid UTF-8 characters: 3, 4, 5, 6, 7, 8, ...
2: In read_utf8(file) :
  The file pandoc4e7e51bc8afc is not encoded in UTF-8. These lines contain invalid UTF-8 characters: 3, 4, 5, 6, 7, 8, ...
3: In readLines(con, warn = FALSE) :
  invalid input found on input connection '04-oxthesis.knit.md'
Execution halted
Warning message:
In file.remove(intermediate_html) :
  cannot remove file '04-oxthesis.utf8.tmp.html', reason 'No such file or directory'

It might also be worth noting that custom blocks rely on echo=TRUE. I had to add this to my correction blocks, as I'd set echo=FALSE globally, something you're likely to do in a thesis.

ulyngs commented 3 years ago

Thanks for flagging this - apologies for the delay.

It seems custom blocks cannot be included in Word output. I've pushed a fix (the correction block example now has the chunk options block type='correction', include=knitr::is_latex_output() | knitr::is_html_output()). I also allowed HTML stuff to be included in word output (always_allow_html: true in index.Rmd), which make the Word output more likely to compile come hell or high water. :)

I have not paid much attention to the word output - I very much welcome pull requests with e.g. a nice template for Word output, or implementation of correction highlighting via officer or officedown!