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 80 forks source link

Japanese #42

Closed kizen777 closed 1 year ago

kizen777 commented 2 years ago

I would like to use it for my thesis in Japanese, but to output it in Japanese on your template, it was garbled.

I have just started using Rstudio and found your excellent template in RMarkdown and would be happy to modify it to my graduate school of Health and Sports Sciences format for use.

ulyngs commented 2 years ago

Thanks for flagging this! :)

Can you show me an example of Japanese input, and the garbled output, so I can have a look at what the issue is?

kizen777 commented 2 years ago

The part before "Why use it?" in the Introduction is now in Japanese as attached. BTW, Is this the correct way to contact you?

#########################################

options for knitting a single chapter

#########################################

オックスフォード大学で自分の博士論文を書く際に作成したRMark-down用の論文テンプレート、oxforddown [@lyngsOxforddown2019]へようこそ。このテンプレートでは、RMarkdownで書きながら、美しく実績のあるOxThesisLaTeXテンプレートでPDF出力をフォーマットすることができ,かつ,長い間使われてきた美しいOxThesisLaTeXテンプレートでPDF出力をフォーマットすることができます。my own PhD thesis at the University of Oxford. もしあなたがTeXやLaTeXを使ったことがないのであればR Markdownで論文を書くことで、OxThesisテンプレートへのより良いインターフェイスを提供できることを願っています。さらに重要なことは、R Markdownを使うと、論文の中にコードの塊を埋め込むことができ、コピー&ペーストの手順を避けて、基礎となるデータから直接プロットや表を生成することができるということです。これにより、再現可能な研究を行う習慣が身に付き、研究者としての長期的な利益となり、将来的にあなたの結果を再現したり構築したりしようとする人の助けにもなるのです。

Why use it? {.unnumbered}

-------Error message------ processing file: 00-introduction.Rmd output file: 00-introduction.knit.md

! Package inputenc Error: Unicode character オ (U+30AA) (inputenc) not set up for use with LaTeX.

Try other LaTeX engines instead (e.g., xelatex) if you are using pdflatex. See https://bookdown.org/yihui/rmarkdown-cookbook/latex-unicode.html エラー: LaTeX failed to compile 00-introduction.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See 00-introduction.log for more info. 追加情報: 警告メッセージ: 1: grep("^\s*$", x) で: 入力文字列 1824 はこのロケールでは不適切です 2: grep("^! ", x) で: 入力文字列 1824 はこのロケールでは不適切です 実行が停止されました

kizen777 commented 2 years ago

Fonts are specified: "MS Mincho" for Japanese and Times "New Roman for Roman" for Europe, US matters.

ulyngs commented 2 years ago

I just looked into this:

As per this latex stack exchange, one way to write Japanese characters in LaTeX is to

To do this with oxforddown, adjust the 'output details' section of index.Rmd to the following:

header-includes:
  - \usepackage{xeCJK}
output:
  bookdown::pdf_book:
    latex_engine: xelatex
    citation_pa... (etc.)

Does this work?

kizen777 commented 2 years ago

before input, Japanese characters got an Error message: register() で: Can't find generic scale_type in package ggplot2 to register S3 method. yaml::yaml.load(..., eval.expr = TRUE) でエラー: Parser error: while parsing a block collection at line 152, column 3 did not find expected '-' indicator at line 153, column 3 呼び出し: ... parse_yaml_front_matter -> yaml_load -> 実行が停止されました When I add #####################

output details

##################### header-includes: -\usepackage{xeCJK} output: bookdown::pdf_book: latex_engine: xelatex citation_package: biblatex

macOS Big Sur 11.5.2, XQuartz 2.8.1(xorg-server 1.20.11) R version 4.1.3(2022-03-10) -- "One Push-Up" RStudio 1.4.1717

ulyngs commented 2 years ago

Can you confirm that you used exactly the same indentation as in my example above? It seems like this is just a parsing error of the YAML header. So, for example, you must put two spaces before " - \usepackage{xeCJK}".

As a starting point, try creating a new, R Markdown file that contains only the following, and knit it:

---
header-includes:
  - \usepackage{xeCJK}
output: 
  pdf_document:
    latex_engine: xelatex
---

オックスフォ

Can you confirm that this works?

kizen777 commented 2 years ago

I did a new RMarkdown with only 4 lines and put two spaces before " -\usepackage{xeCJK} then showed the following;

The following objects are masked from 'package:base':

errorCondition

Error message:

Can't find generic scale_type in package ggplot2 to register S3 method. |......................................................................| 100% ordinary text without R code

/Applications/RStudio.app/Contents/MacOS/pandoc/pandoc +RTS -K512m -RTS test_Japanese_character.knit.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output test_Japanese_character.html --lua-filter /Library/Frameworks/R.framework/Versions/4.1/Resources/library/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /Library/Frameworks/R.framework/Versions/4.1/Resources/library/rmarkdown/rmarkdown/lua/latex-div.lua --self-contained --variable bs3=TRUE --standalone --section-divs --template /Library/Frameworks/R.framework/Versions/4.1/Resources/library/rmarkdown/rmd/h/default.html --no-highlight --variable highlightjs=1 --variable theme=bootstrap --mathjax --variable 'mathjax-url=https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' --include-in-header /var/folders/vg/yh8xwzx52dq7dy_mzblw7dl40000gn/T//RtmpGcI3iC/rmarkdown-str28fe35ba391d.html

processing file: test_Japanese_character.Rmd output file: test_Japanese_character.knit.md

[WARNING] This document format requires a nonempty element. Defaulting to 'test_Japanese_character.knit' as the title. To specify a title, use 'title' in metadata or --metadata title="...".</p> <p>Output created: test_Japanese_character.html</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/ulyngs"><img src="https://avatars.githubusercontent.com/u/23137032?v=4" />ulyngs</a> commented <strong> 1 year ago</strong> </div> <div class="markdown-body"> <p>Can you show me the content of the entire R Markdown file you created, and I'll try to reproduce the error?</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/kizen777"><img src="https://avatars.githubusercontent.com/u/32872346?v=4" />kizen777</a> commented <strong> 1 year ago</strong> </div> <div class="markdown-body"> <p>Do you mean this?</p> <p>I put my name on the index.Rmd autohor: Author Name to my Japanese name.</p> <p>output file: _main.knit.md</p> <p>/Applications/RStudio.app/Contents/MacOS/quarto/bin/tools/pandoc +RTS -K512m -RTS _main.knit.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output _main.tex --lua-filter /Library/Frameworks/R.framework/Versions/4.2/Resources/library/bookdown/rmarkdown/lua/custom-environment.lua --lua-filter /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rmarkdown/rmarkdown/lua/latex-div.lua --metadata-file /var/folders/vg/yh8xwzx52dq7dy_mzblw7dl40000gn/T//RtmpBQ1e7r/file5f057f7cea26 --embed-resources --standalone --table-of-contents --toc-depth 2 --template templates/template.tex --number-sections --highlight-style tango --pdf-engine pdflatex --biblatex --wrap preserve --lua-filter=scripts_and_filters/colour_and_highlight.lua --include-in-header /var/folders/vg/yh8xwzx52dq7dy_mzblw7dl40000gn/T//RtmpBQ1e7r/rmarkdown-str5f05df44a40.html --variable tables=yes --standalone -Mhas-frontmatter=false 警告: Package fancyhdr Warning: \fancyhead's <code>E' option without twoside option is useless. 警告: (fancyhdr) Please consider using the</code>twoside' option on input line 177. 警告: LaTeX Warning: Command <strong><em>@</em></strong>.*** has changed. 警告: Check if current package is valid. 警告: Package fvextra Warning: csquotes should be loaded after fvextra, to avoid a warning from the lineno package on input line 37. 警告: Package biblatex Warning: Language 'latin' not supported. 警告: (biblatex) Using dummy definitions on input line 261.</p> <p>Output created: docs/_main.pdf 警告メッセージ: 1: get_engine(options$engine) で: Unknown language engine 'yaml' (must be registered via knit_engines$set()). 2: get_engine(options$engine) で: Unknown language engine 'yaml' (must be registered via knit_engines$set()). 3: get_engine(options$engine) で: Unknown language engine 'yaml' (must be registered via knit_engines$set()).</p> <blockquote> <p>2022/12/07 21:21、Ulrik Lyngs <strong><em>@</em></strong>.***>のメール:</p> <p>Can you show me the content of the entire R Markdown file you created, and I'll try to reproduce the error?</p> <p>— Reply to this email directly, view it on GitHub <a href="https://github.com/ulyngs/oxforddown/issues/42#issuecomment-1340889454">https://github.com/ulyngs/oxforddown/issues/42#issuecomment-1340889454</a>, or unsubscribe <a href="https://github.com/notifications/unsubscribe-auth/AH2ZPGU5A7Y5FOXI2F3DUJ3WMB6NPANCNFSM5REQVV6Q">https://github.com/notifications/unsubscribe-auth/AH2ZPGU5A7Y5FOXI2F3DUJ3WMB6NPANCNFSM5REQVV6Q</a>. You are receiving this because you modified the open/close state.</p> </blockquote> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/ulyngs"><img src="https://avatars.githubusercontent.com/u/23137032?v=4" />ulyngs</a> commented <strong> 1 year ago</strong> </div> <div class="markdown-body"> <p>No, I meant can you confirm that you put <em>only</em> this content in a brand-new R Markdown file in a brand-new project?</p> <pre><code class="language-markdown">--- header-includes: - \usepackage{xeCJK} output: pdf_document: latex_engine: xelatex --- オックスフォ</code></pre> <p>So forgetting everything about <code>oxforddown</code> for a minute, are you normally able to use Japanese characters in R Markdown documents and output to PDF without any issues?</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/kizen777"><img src="https://avatars.githubusercontent.com/u/32872346?v=4" />kizen777</a> commented <strong> 1 year ago</strong> </div> <div class="markdown-body"> <p>Oh, sorry. Thereafter I started to try to use quarto but stoped after August.</p> <p>Japanese can use in the text, but not for graphs and figures.</p> <p>Thanks and regards,</p> <p>Kizen</p> <blockquote> <p>2022/12/09 21:13、Ulrik Lyngs <strong><em>@</em></strong>.***>のメール:</p> <p>No, I meant can you confirm that you put only this content in a brand-new R Markdown file in a brand-new project?</p> <hr /> <p>header-includes:</p> <ul> <li> <h2>\usepackage{xeCJK} output: pdf_document: latex_engine: xelatex</h2> </li> </ul> <p>オックスフォ So forgetting everything about oxforddown for a minute, are you normally able to use Japanese characters in R Markdown documents and output to PDF without any issues?</p> <p>— Reply to this email directly, view it on GitHub <a href="https://github.com/ulyngs/oxforddown/issues/42#issuecomment-1344234119">https://github.com/ulyngs/oxforddown/issues/42#issuecomment-1344234119</a>, or unsubscribe <a href="https://github.com/notifications/unsubscribe-auth/AH2ZPGQLZFCV3MJOYM3HDHDWMMO63ANCNFSM5REQVV6Q">https://github.com/notifications/unsubscribe-auth/AH2ZPGQLZFCV3MJOYM3HDHDWMMO63ANCNFSM5REQVV6Q</a>. You are receiving this because you modified the open/close state.</p> </blockquote> </div> </div> <div class="page-bar-simple"> </div> <div class="footer"> <ul class="body"> <li>© <script> document.write(new Date().getFullYear()) </script> Githubissues.</li> <li>Githubissues is a development platform for aggregating issues.</li> </ul> </div> <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script> <script src="/githubissues/assets/js.js"></script> <script src="/githubissues/assets/markdown.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/highlight.min.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/go.min.js"></script> <script> hljs.highlightAll(); </script> </body> </html>