{"id":20667886,"url":"https://github.com/statnmap/rmarkdown_tips","last_synced_at":"2025-10-12T18:05:39.669Z","repository":{"id":117563202,"uuid":"84576066","full_name":"statnmap/Rmarkdown_tips","owner":"statnmap","description":"Rmarkdown conditional chunks to create multilingual pdf and html with images","archived":false,"fork":false,"pushed_at":"2017-10-24T14:51:46.000Z","size":1965,"stargazers_count":4,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-14T19:04:59.320Z","etag":null,"topics":["knitr","r","rmarkdown"],"latest_commit_sha":null,"homepage":"https://statnmap.com/2017/03/rmarkdown-conditional-chunks-to-create-multilingual-pdf-and-html-with-images/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/statnmap.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-03-10T15:54:00.000Z","updated_at":"2022-01-30T19:52:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"866f32de-4c5d-4b90-9055-8f806dee7d92","html_url":"https://github.com/statnmap/Rmarkdown_tips","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/statnmap/Rmarkdown_tips","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statnmap%2FRmarkdown_tips","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statnmap%2FRmarkdown_tips/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statnmap%2FRmarkdown_tips/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statnmap%2FRmarkdown_tips/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/statnmap","download_url":"https://codeload.github.com/statnmap/Rmarkdown_tips/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statnmap%2FRmarkdown_tips/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279012472,"owners_count":26085131,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["knitr","r","rmarkdown"],"created_at":"2024-11-16T19:45:28.173Z","updated_at":"2025-10-12T18:05:39.652Z","avatar_url":"https://github.com/statnmap.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rmarkdown conditional chunks to create multilingual pdf and html with images\n[https://statnmap.com/](https://statnmap.com/2017-03-11-rmarkdown-conditional-chunks-to-create-multilingual-pdf-and-html-with-images)  \n\n\u003cimg src=\"./myfigdirectory/gb.png\" width=\"24\" /\u003e This version is the english version.  \n\n# Knit with multiple rendering options\nI want to be able to knit my rmarkdown documents in different speaking language (english and french). I also want them to give similar rendering in html and in latex pdf so that I can use them in my courses as html version on the laptop, but also as printed version through the latex pdf. By the way, I also have a teacher and a student version for the R-scripts that I can purl from the Rmd file.  \nThis means many options for a **unique** rmarkdown document. Using a unique document allow me to directly modify things for the different versions at the same place. I do not have to jump from a file to another and verify that I copied every modification in the R-script or other...  \nI personnaly use an external _\"run-all\"_ R-script to choose options to run the different versions and rename output files.\n\n# A non exhaustive list\nIn this article, I list some of the tips I have to use to make this work and some bonus:\n\n- Use chunks options to render text according to speaking language chosen,\n- Use functions to render text color, background or format similar in pdf and html outputs,\n- Print inline (or not) images depending on speaking language,\n    + Render two images side by side and centered on the page for html and pdf,\n- Allow verbatim chunk environment with background color for html and pdf,\n- Output R-script included in chunks for tutorials, with different versions for teacher and students.\n\n# Output files in pdf, html, french and english\nThe [tutorial is presented on my website](https://statnmap.com/2017-03-11-rmarkdown-conditional-chunks-to-create-multilingual-pdf-and-html-with-images), but the complete outputs are here on this github repository:\n\n- Rmd_tips_EN.html: HTML english version\n- Rmd_tips_FR.html: HTML french version\n- Rmd_tips_EN.pdf: PDF english version\n- Rmd_tips_FR.pdf: PDF french version\n\n\n# Table of content\n1. Knit with multiple rendering options\n    - 1.1 A non exhaustive list\n    - 1.2 Functions for html or pdf specific rendering\n2. Choose a language to knit\n    - 2.1 Embed text in 'asis' chunks\n        + 2.1.1 For titles and subtitles when at the beginning\n        + 2.1.2 And for titles in the middle if there is space line above \n    - 2.2 Include R outputs in conditional chunk\n        + 2.2.1 Example of title in a chunk\n    - 2.3 Conditional images and path\n        + 2.3.1 When images are in a defined directory and are shown in paragraph different that text\n        + 2.3.2 When images are in a changing directory and are shown inline\n3. Two images side-by-side and centered\n4. Student and teacher versions\n    - 4.1 Create the tutorial roadmap\n        + 4.1.1 Exercise example\n    - 4.2 Purl the rmarkdown file\n5. Try this script !\n    - 5.1 Some limits\n6. Supplemental tips\n\n***\nMore tips on [R, models and spatial things on my website](https://statnmap.com/)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatnmap%2Frmarkdown_tips","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstatnmap%2Frmarkdown_tips","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatnmap%2Frmarkdown_tips/lists"}