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

Breaking a page at the final line of the page adds a blank page in word_document #1752

Open
3 tasks done
atusy opened this issue Dec 29, 2019 · 7 comments · May be fixed by #1753
Open
3 tasks done

Breaking a page at the final line of the page adds a blank page in word_document #1752

atusy opened this issue Dec 29, 2019 · 7 comments · May be fixed by #1753
Labels
feature a feature request or enhancement theme: lua probably related to lua filter

Comments

@atusy
Copy link
Contributor

atusy commented Dec 29, 2019

Currently \newpage must be a paragraph composed only by itself like

Paragraph

\newpage

Paragraph

This may add a blank page in word_document when the paragraph before breaking page reaches at the bottom of a page.

image

It would be nice if pagebreak can be done as a part of paragraph.
For example by

This paragraph ends with pagebreak.
\newpage

reprex

---
output:
  word_document:
    md_extensions: "+hard_line_breaks"
---

```{r, echo=FALSE, results='asis'}
cat(rep("1st page", 42), sep = "\n")
```

\newpage

Blank page exists before this line.

xfun::session_info('rmarkdown')

R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763), RStudio 1.2.1335

Locale:
  LC_COLLATE=Japanese_Japan.932  LC_CTYPE=Japanese_Japan.932   
  LC_MONETARY=Japanese_Japan.932 LC_NUMERIC=C                  
  LC_TIME=Japanese_Japan.932    

Package version:
  base64enc_0.1.3 digest_0.6.23   evaluate_0.14   glue_1.3.1     
  graphics_3.6.1  grDevices_3.6.1 highr_0.8       htmltools_0.4.0
  jsonlite_1.6    knitr_1.26      magrittr_1.5    markdown_1.1   
  methods_3.6.1   mime_0.8        Rcpp_1.0.3      rlang_0.4.2    
  rmarkdown_2.0.5 stats_3.6.1     stringi_1.4.3   stringr_1.4.0  
  tinytex_0.18    tools_3.6.1     utils_3.6.1     xfun_0.11      
  yaml_2.2.0     

Pandoc version: 2.7.3
---

By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('rmarkdown'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('rstudio/rmarkdown').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

@cderv
Copy link
Collaborator

cderv commented Dec 29, 2019

What is your version of Office ?

I can't reproduce on my windows 10 with Office 2016. There is no blank page before the line in your example. 🤔

@atusy
Copy link
Contributor Author

atusy commented Dec 29, 2019

I am also using Windows 10 and Office 2016.
Does first paragraph repeating "1st page" reach at the bottom of the first page?

@atusy
Copy link
Contributor Author

atusy commented Dec 30, 2019

Here's the docx rendered by my example Rmd.
test.docx

@cderv
Copy link
Collaborator

cderv commented Dec 30, 2019

Thank you. I don't know how Word works internally but when I open your document I only got 2 pages and no blank page in the middle. This is your document open on my PC:
image

@atusy
Copy link
Contributor Author

atusy commented Dec 30, 2019

Thanks for the report. Would you take another screenshot with formatting marks?

@cderv
Copy link
Collaborator

cderv commented Jan 1, 2020

Ok I need to add 3 more "1st page" to reproduce. Now I see what you encounter.

Currently, the pagebreak feature is completly inspired from the pagebreak pandoc lua filter that works only by finding \newpage or \pagebreak keyword in its own paragraph. That allows to add pagebreak specific syntax in a wide variety of formats.
The lua filter would need to be modified in order to try detect the keyword inside a paragraph. Could be possible, and then would be needed to be tested through all the format...

For now, I think the word document would need to be manually post process if a blank page is created in the very specific case you encountered. Otherwise, officedown is also a great way to use rmarkdown for docx document.

@cderv
Copy link
Collaborator

cderv commented Jan 1, 2020

The lua filter would need to be modified in order to try detect the keyword inside a paragraph.

Ok I manage to write a lua script that work with inline \newpage or \pagebreak command. It works well for docx document, and fix your example.

then would be needed to be tested through all the format

Currently, in the pagebreak filter, the code to create the pagebreak in the different format is inserted as pandoc RawBlock. I don't know if RawInline will work for every format and it needs to be tested thoroughly.

Or we just decide to activate RawInline insertion for docx format. I have done that for now.

@cderv cderv linked a pull request Jan 1, 2020 that will close this issue
@cderv cderv added theme: lua probably related to lua filter feature a feature request or enhancement labels Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement theme: lua probably related to lua filter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants