GithubHelp home page GithubHelp logo

Comments (7)

davidgohel avatar davidgohel commented on June 18, 2024 1

---
title: "Untitled"
output:
  officedown::rdocx_document:
    default
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

# Chapter1 {#ch1}

# Chapter2 {#ch2}

Refer to \@ref(ch1).

When \@ref(ch1) is surrounded by multibyte strings (e.g., Chinese characters), it would possibly encounter errors.

- Pure multibyte + ref: 上下\@ref(ch1)
- Example: 上a下\@ref(ch1)
- ref + multibyte: \@ref(ch1)。

Your issue is related to the fact you are not working with a UTF-8 encoded file.

R, R Markdown and Windows does not work well when encoding is not UTF-8.

Capture d’écran 2020-08-27 à 10 53 27

Untitled.docx

from officedown.

bishun945 avatar bishun945 commented on June 18, 2024 1

Hi @madlogos,

I am aslo a Chinese user. The multibyte problem has also bothered me for a long time. Here is my trick for it:

  1. Write @ref as usual;
  2. Save the Rmd file and readr::read_lines it;
  3. Match the strings containing "\\\\@ref\\([^\\)]+\\)" pattern;
  4. Split it and make sure the "\\\\@ref\\([^\\)]+\\)" on a single line;
  5. Save the character vector to a new Rmd file and render it with the format you like. Done!

For example, 请参考表\@ref(tab: coco)中的数据 should be splited as
[line 1] 请参考表
[line 2] \@ref(tab: coco)
[line 3] 中的数据

Well, I am not sure if this is an effective solution but it works for me. 😄

from officedown.

madlogos avatar madlogos commented on June 18, 2024

Yes, @davidgohel, you are right. Althougth the .Rmd file is in UTF-8, the OS is running on GBK encoding. When I change to bookdown::word_document2, the knitr engine manages to compile the file. But I still get ?? where the bookmark is supposed to appear.

from officedown.

davidgohel avatar davidgohel commented on June 18, 2024

You don't need to try new output format functions.

The result shown below is made with a Windows with french locale. But I made sure the file was encoded as UTF-8 (I am using readr::guess_encoding(), if not UTF-8 encoded, I can change it to UTF8 with fpeek::peek_iconv()).

Could you show the result of

readr::guess_encoding("your/rmd/file")

from officedown.

madlogos avatar madlogos commented on June 18, 2024

The results are

no encoding confidence
1 UTF-8 1
2 windows-1252 0.28

from officedown.

madlogos avatar madlogos commented on June 18, 2024

@bishun945 thank you for the turn-around. Good stuff.

from officedown.

bishun945 avatar bishun945 commented on June 18, 2024

@madlogos I have tried another solution: just switch your system and MS Word language to English.

from officedown.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.