Problem with foreign characters: some work (äöüßĐØ), some not (ČĈĐĎŸ) [RStudio+knitr+XeLaTex]
up vote
3
down vote
favorite
I want to print some foreign characters in my final PDF produced with
RStudio (0.99) + *.Rnw-File with knitr + XeLaTex (via Miktex).
While using XeLaTex and polyglossia I can manage that all foreign characters are print properly in the PDF, if I pass it directly to the Tex-environment of the *.Rnw-File.
If I use the Cat("...")-function to print text in the PDF within a R-chunk, it fails in some characters ("1."), in others not ("2....").
I use utf8 enconding in the RStudio settings which obviously works well inside Tex-environment. But why does the cat-expression inside the R-chunk dont like the same characters?
What can I do to use cat("...") expression (I frequently used) also for the foreign characters?
MWE:
documentclass[utf8, a4paper]{article} % with/without [utf8] does not change anything
% !Rnw weave = knitr
% !TeX program = XeLaTeX
usepackage{polyglossia}
setmainlanguage{english}
usepackage{fontspec}
begin{document}
Directly passed in tex environment:
1. äöüßĐØ
2. ČĈĐĎŸ
<<echo=FALSE, results = 'asis'>>=
cat("Within a R-Knitr-Junk: \newline")
cat("1. äöüßĐØ ~")
cat("2. ČĈĐĎŸ")
@
end{document}
PDF-Result:
Checking the tex-file produced by RSTudio (using Notepad++ with utf8 support) the line inside the R-chunk looks like:
OS: Win7/64Bit, RStudio 0.99 , R 3.2.5, MikTex 2.9.5900
xetex knitr rstudio
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
up vote
3
down vote
favorite
I want to print some foreign characters in my final PDF produced with
RStudio (0.99) + *.Rnw-File with knitr + XeLaTex (via Miktex).
While using XeLaTex and polyglossia I can manage that all foreign characters are print properly in the PDF, if I pass it directly to the Tex-environment of the *.Rnw-File.
If I use the Cat("...")-function to print text in the PDF within a R-chunk, it fails in some characters ("1."), in others not ("2....").
I use utf8 enconding in the RStudio settings which obviously works well inside Tex-environment. But why does the cat-expression inside the R-chunk dont like the same characters?
What can I do to use cat("...") expression (I frequently used) also for the foreign characters?
MWE:
documentclass[utf8, a4paper]{article} % with/without [utf8] does not change anything
% !Rnw weave = knitr
% !TeX program = XeLaTeX
usepackage{polyglossia}
setmainlanguage{english}
usepackage{fontspec}
begin{document}
Directly passed in tex environment:
1. äöüßĐØ
2. ČĈĐĎŸ
<<echo=FALSE, results = 'asis'>>=
cat("Within a R-Knitr-Junk: \newline")
cat("1. äöüßĐØ ~")
cat("2. ČĈĐĎŸ")
@
end{document}
PDF-Result:
Checking the tex-file produced by RSTudio (using Notepad++ with utf8 support) the line inside the R-chunk looks like:
OS: Win7/64Bit, RStudio 0.99 , R 3.2.5, MikTex 2.9.5900
xetex knitr rstudio
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
1
This is a question about the Rcat
function, not about TeX.
– Thruston
Apr 26 '17 at 7:28
Thanks to your suggestion I have checked with the RStudio console and cat("ČĈĐĎŸ") and print("ČĈĐĎŸ") both produce "CCÐDŸ" out of the box. This differs to the above posted example only in the "Ÿ" which is missing above. Until no I could not find a soluten to properly print these signs inside the console. You suggest to post it to another forum, right (which?)?
– therob
Apr 26 '17 at 8:34
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I want to print some foreign characters in my final PDF produced with
RStudio (0.99) + *.Rnw-File with knitr + XeLaTex (via Miktex).
While using XeLaTex and polyglossia I can manage that all foreign characters are print properly in the PDF, if I pass it directly to the Tex-environment of the *.Rnw-File.
If I use the Cat("...")-function to print text in the PDF within a R-chunk, it fails in some characters ("1."), in others not ("2....").
I use utf8 enconding in the RStudio settings which obviously works well inside Tex-environment. But why does the cat-expression inside the R-chunk dont like the same characters?
What can I do to use cat("...") expression (I frequently used) also for the foreign characters?
MWE:
documentclass[utf8, a4paper]{article} % with/without [utf8] does not change anything
% !Rnw weave = knitr
% !TeX program = XeLaTeX
usepackage{polyglossia}
setmainlanguage{english}
usepackage{fontspec}
begin{document}
Directly passed in tex environment:
1. äöüßĐØ
2. ČĈĐĎŸ
<<echo=FALSE, results = 'asis'>>=
cat("Within a R-Knitr-Junk: \newline")
cat("1. äöüßĐØ ~")
cat("2. ČĈĐĎŸ")
@
end{document}
PDF-Result:
Checking the tex-file produced by RSTudio (using Notepad++ with utf8 support) the line inside the R-chunk looks like:
OS: Win7/64Bit, RStudio 0.99 , R 3.2.5, MikTex 2.9.5900
xetex knitr rstudio
I want to print some foreign characters in my final PDF produced with
RStudio (0.99) + *.Rnw-File with knitr + XeLaTex (via Miktex).
While using XeLaTex and polyglossia I can manage that all foreign characters are print properly in the PDF, if I pass it directly to the Tex-environment of the *.Rnw-File.
If I use the Cat("...")-function to print text in the PDF within a R-chunk, it fails in some characters ("1."), in others not ("2....").
I use utf8 enconding in the RStudio settings which obviously works well inside Tex-environment. But why does the cat-expression inside the R-chunk dont like the same characters?
What can I do to use cat("...") expression (I frequently used) also for the foreign characters?
MWE:
documentclass[utf8, a4paper]{article} % with/without [utf8] does not change anything
% !Rnw weave = knitr
% !TeX program = XeLaTeX
usepackage{polyglossia}
setmainlanguage{english}
usepackage{fontspec}
begin{document}
Directly passed in tex environment:
1. äöüßĐØ
2. ČĈĐĎŸ
<<echo=FALSE, results = 'asis'>>=
cat("Within a R-Knitr-Junk: \newline")
cat("1. äöüßĐØ ~")
cat("2. ČĈĐĎŸ")
@
end{document}
PDF-Result:
Checking the tex-file produced by RSTudio (using Notepad++ with utf8 support) the line inside the R-chunk looks like:
OS: Win7/64Bit, RStudio 0.99 , R 3.2.5, MikTex 2.9.5900
xetex knitr rstudio
xetex knitr rstudio
edited May 3 '17 at 13:00
asked Apr 26 '17 at 7:08
therob
162
162
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
1
This is a question about the Rcat
function, not about TeX.
– Thruston
Apr 26 '17 at 7:28
Thanks to your suggestion I have checked with the RStudio console and cat("ČĈĐĎŸ") and print("ČĈĐĎŸ") both produce "CCÐDŸ" out of the box. This differs to the above posted example only in the "Ÿ" which is missing above. Until no I could not find a soluten to properly print these signs inside the console. You suggest to post it to another forum, right (which?)?
– therob
Apr 26 '17 at 8:34
add a comment |
1
This is a question about the Rcat
function, not about TeX.
– Thruston
Apr 26 '17 at 7:28
Thanks to your suggestion I have checked with the RStudio console and cat("ČĈĐĎŸ") and print("ČĈĐĎŸ") both produce "CCÐDŸ" out of the box. This differs to the above posted example only in the "Ÿ" which is missing above. Until no I could not find a soluten to properly print these signs inside the console. You suggest to post it to another forum, right (which?)?
– therob
Apr 26 '17 at 8:34
1
1
This is a question about the R
cat
function, not about TeX.– Thruston
Apr 26 '17 at 7:28
This is a question about the R
cat
function, not about TeX.– Thruston
Apr 26 '17 at 7:28
Thanks to your suggestion I have checked with the RStudio console and cat("ČĈĐĎŸ") and print("ČĈĐĎŸ") both produce "CCÐDŸ" out of the box. This differs to the above posted example only in the "Ÿ" which is missing above. Until no I could not find a soluten to properly print these signs inside the console. You suggest to post it to another forum, right (which?)?
– therob
Apr 26 '17 at 8:34
Thanks to your suggestion I have checked with the RStudio console and cat("ČĈĐĎŸ") and print("ČĈĐĎŸ") both produce "CCÐDŸ" out of the box. This differs to the above posted example only in the "Ÿ" which is missing above. Until no I could not find a soluten to properly print these signs inside the console. You suggest to post it to another forum, right (which?)?
– therob
Apr 26 '17 at 8:34
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
It may be related with the font you're system is using to output the code, it is generally another font than the one for the normal text. It is also dependent from your system, so you may have to follow these two steps
What happen if you add this line to your latex preamble after usepackage{fontspec}
?
usepackage{libertine}
And you may have to use special escape unicode character in your R code, it is more robust. That is for example ß
cat("u00DF")
# ß
and the easiest way to do that is to use stringi::stri_escape_unicode()
stringi::stri_escape_unicode("ČĈĐĎŸ")
# u010cu0108u0110u010eu0178
See https://stackoverflow.com/questions/29265172/print-unicode-character-string-in-r
Thanks for you hints. - Did I get it right: you suggests to use "u00DF" instead of "ß" etc? Not very practical as I have to care about all foreign characters manually (by find&replace).... - I would prefer that this can be done "automatic" .... as I have also no problems with german umlauts äöüß --> why no way for croatian characters?
– therob
Apr 27 '17 at 8:26
- Meanwhile I did some other progress - but still not perfect: 1.) I followed r-bloggers.com/r-and-foreign-characters and using now inside the R-chunk (or in the R-console while debugging) --> Sys.setlocale("LC_CTYPE", "croatian") <- 2.) Now most of the croatian characters are drawn correctly, but not all. Any other advice with this approach? 3.) using "pdf.options(encoding = 'ISOLatin2') # or utf8, latin1..." did not bring any improvement
– therob
Apr 27 '17 at 8:28
@therob Did you tryusepackage{libertine}
? Can you edit your answer to add your OS+version of programm/Package. It works fiine on my debian 9
– nebi
Apr 27 '17 at 15:27
Update: after using sys.setlocale("..") (see above comment) most, but not all characters I mentioned are displayed properly. Funny thing is, that with the same source code all characters worked properly, after using another PC (Windows8.1) in croatia. Maybe there is any croatian package/characterset/keyboardlayout installed, which was not the case in my german test-PC before? I could not figure out why it worked, but it did without further measures from my side....strange...
– therob
May 15 '17 at 12:03
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
It may be related with the font you're system is using to output the code, it is generally another font than the one for the normal text. It is also dependent from your system, so you may have to follow these two steps
What happen if you add this line to your latex preamble after usepackage{fontspec}
?
usepackage{libertine}
And you may have to use special escape unicode character in your R code, it is more robust. That is for example ß
cat("u00DF")
# ß
and the easiest way to do that is to use stringi::stri_escape_unicode()
stringi::stri_escape_unicode("ČĈĐĎŸ")
# u010cu0108u0110u010eu0178
See https://stackoverflow.com/questions/29265172/print-unicode-character-string-in-r
Thanks for you hints. - Did I get it right: you suggests to use "u00DF" instead of "ß" etc? Not very practical as I have to care about all foreign characters manually (by find&replace).... - I would prefer that this can be done "automatic" .... as I have also no problems with german umlauts äöüß --> why no way for croatian characters?
– therob
Apr 27 '17 at 8:26
- Meanwhile I did some other progress - but still not perfect: 1.) I followed r-bloggers.com/r-and-foreign-characters and using now inside the R-chunk (or in the R-console while debugging) --> Sys.setlocale("LC_CTYPE", "croatian") <- 2.) Now most of the croatian characters are drawn correctly, but not all. Any other advice with this approach? 3.) using "pdf.options(encoding = 'ISOLatin2') # or utf8, latin1..." did not bring any improvement
– therob
Apr 27 '17 at 8:28
@therob Did you tryusepackage{libertine}
? Can you edit your answer to add your OS+version of programm/Package. It works fiine on my debian 9
– nebi
Apr 27 '17 at 15:27
Update: after using sys.setlocale("..") (see above comment) most, but not all characters I mentioned are displayed properly. Funny thing is, that with the same source code all characters worked properly, after using another PC (Windows8.1) in croatia. Maybe there is any croatian package/characterset/keyboardlayout installed, which was not the case in my german test-PC before? I could not figure out why it worked, but it did without further measures from my side....strange...
– therob
May 15 '17 at 12:03
add a comment |
up vote
0
down vote
It may be related with the font you're system is using to output the code, it is generally another font than the one for the normal text. It is also dependent from your system, so you may have to follow these two steps
What happen if you add this line to your latex preamble after usepackage{fontspec}
?
usepackage{libertine}
And you may have to use special escape unicode character in your R code, it is more robust. That is for example ß
cat("u00DF")
# ß
and the easiest way to do that is to use stringi::stri_escape_unicode()
stringi::stri_escape_unicode("ČĈĐĎŸ")
# u010cu0108u0110u010eu0178
See https://stackoverflow.com/questions/29265172/print-unicode-character-string-in-r
Thanks for you hints. - Did I get it right: you suggests to use "u00DF" instead of "ß" etc? Not very practical as I have to care about all foreign characters manually (by find&replace).... - I would prefer that this can be done "automatic" .... as I have also no problems with german umlauts äöüß --> why no way for croatian characters?
– therob
Apr 27 '17 at 8:26
- Meanwhile I did some other progress - but still not perfect: 1.) I followed r-bloggers.com/r-and-foreign-characters and using now inside the R-chunk (or in the R-console while debugging) --> Sys.setlocale("LC_CTYPE", "croatian") <- 2.) Now most of the croatian characters are drawn correctly, but not all. Any other advice with this approach? 3.) using "pdf.options(encoding = 'ISOLatin2') # or utf8, latin1..." did not bring any improvement
– therob
Apr 27 '17 at 8:28
@therob Did you tryusepackage{libertine}
? Can you edit your answer to add your OS+version of programm/Package. It works fiine on my debian 9
– nebi
Apr 27 '17 at 15:27
Update: after using sys.setlocale("..") (see above comment) most, but not all characters I mentioned are displayed properly. Funny thing is, that with the same source code all characters worked properly, after using another PC (Windows8.1) in croatia. Maybe there is any croatian package/characterset/keyboardlayout installed, which was not the case in my german test-PC before? I could not figure out why it worked, but it did without further measures from my side....strange...
– therob
May 15 '17 at 12:03
add a comment |
up vote
0
down vote
up vote
0
down vote
It may be related with the font you're system is using to output the code, it is generally another font than the one for the normal text. It is also dependent from your system, so you may have to follow these two steps
What happen if you add this line to your latex preamble after usepackage{fontspec}
?
usepackage{libertine}
And you may have to use special escape unicode character in your R code, it is more robust. That is for example ß
cat("u00DF")
# ß
and the easiest way to do that is to use stringi::stri_escape_unicode()
stringi::stri_escape_unicode("ČĈĐĎŸ")
# u010cu0108u0110u010eu0178
See https://stackoverflow.com/questions/29265172/print-unicode-character-string-in-r
It may be related with the font you're system is using to output the code, it is generally another font than the one for the normal text. It is also dependent from your system, so you may have to follow these two steps
What happen if you add this line to your latex preamble after usepackage{fontspec}
?
usepackage{libertine}
And you may have to use special escape unicode character in your R code, it is more robust. That is for example ß
cat("u00DF")
# ß
and the easiest way to do that is to use stringi::stri_escape_unicode()
stringi::stri_escape_unicode("ČĈĐĎŸ")
# u010cu0108u0110u010eu0178
See https://stackoverflow.com/questions/29265172/print-unicode-character-string-in-r
edited May 23 '17 at 12:39
Community♦
1
1
answered Apr 26 '17 at 20:09
nebi
36519
36519
Thanks for you hints. - Did I get it right: you suggests to use "u00DF" instead of "ß" etc? Not very practical as I have to care about all foreign characters manually (by find&replace).... - I would prefer that this can be done "automatic" .... as I have also no problems with german umlauts äöüß --> why no way for croatian characters?
– therob
Apr 27 '17 at 8:26
- Meanwhile I did some other progress - but still not perfect: 1.) I followed r-bloggers.com/r-and-foreign-characters and using now inside the R-chunk (or in the R-console while debugging) --> Sys.setlocale("LC_CTYPE", "croatian") <- 2.) Now most of the croatian characters are drawn correctly, but not all. Any other advice with this approach? 3.) using "pdf.options(encoding = 'ISOLatin2') # or utf8, latin1..." did not bring any improvement
– therob
Apr 27 '17 at 8:28
@therob Did you tryusepackage{libertine}
? Can you edit your answer to add your OS+version of programm/Package. It works fiine on my debian 9
– nebi
Apr 27 '17 at 15:27
Update: after using sys.setlocale("..") (see above comment) most, but not all characters I mentioned are displayed properly. Funny thing is, that with the same source code all characters worked properly, after using another PC (Windows8.1) in croatia. Maybe there is any croatian package/characterset/keyboardlayout installed, which was not the case in my german test-PC before? I could not figure out why it worked, but it did without further measures from my side....strange...
– therob
May 15 '17 at 12:03
add a comment |
Thanks for you hints. - Did I get it right: you suggests to use "u00DF" instead of "ß" etc? Not very practical as I have to care about all foreign characters manually (by find&replace).... - I would prefer that this can be done "automatic" .... as I have also no problems with german umlauts äöüß --> why no way for croatian characters?
– therob
Apr 27 '17 at 8:26
- Meanwhile I did some other progress - but still not perfect: 1.) I followed r-bloggers.com/r-and-foreign-characters and using now inside the R-chunk (or in the R-console while debugging) --> Sys.setlocale("LC_CTYPE", "croatian") <- 2.) Now most of the croatian characters are drawn correctly, but not all. Any other advice with this approach? 3.) using "pdf.options(encoding = 'ISOLatin2') # or utf8, latin1..." did not bring any improvement
– therob
Apr 27 '17 at 8:28
@therob Did you tryusepackage{libertine}
? Can you edit your answer to add your OS+version of programm/Package. It works fiine on my debian 9
– nebi
Apr 27 '17 at 15:27
Update: after using sys.setlocale("..") (see above comment) most, but not all characters I mentioned are displayed properly. Funny thing is, that with the same source code all characters worked properly, after using another PC (Windows8.1) in croatia. Maybe there is any croatian package/characterset/keyboardlayout installed, which was not the case in my german test-PC before? I could not figure out why it worked, but it did without further measures from my side....strange...
– therob
May 15 '17 at 12:03
Thanks for you hints. - Did I get it right: you suggests to use "u00DF" instead of "ß" etc? Not very practical as I have to care about all foreign characters manually (by find&replace).... - I would prefer that this can be done "automatic" .... as I have also no problems with german umlauts äöüß --> why no way for croatian characters?
– therob
Apr 27 '17 at 8:26
Thanks for you hints. - Did I get it right: you suggests to use "u00DF" instead of "ß" etc? Not very practical as I have to care about all foreign characters manually (by find&replace).... - I would prefer that this can be done "automatic" .... as I have also no problems with german umlauts äöüß --> why no way for croatian characters?
– therob
Apr 27 '17 at 8:26
- Meanwhile I did some other progress - but still not perfect: 1.) I followed r-bloggers.com/r-and-foreign-characters and using now inside the R-chunk (or in the R-console while debugging) --> Sys.setlocale("LC_CTYPE", "croatian") <- 2.) Now most of the croatian characters are drawn correctly, but not all. Any other advice with this approach? 3.) using "pdf.options(encoding = 'ISOLatin2') # or utf8, latin1..." did not bring any improvement
– therob
Apr 27 '17 at 8:28
- Meanwhile I did some other progress - but still not perfect: 1.) I followed r-bloggers.com/r-and-foreign-characters and using now inside the R-chunk (or in the R-console while debugging) --> Sys.setlocale("LC_CTYPE", "croatian") <- 2.) Now most of the croatian characters are drawn correctly, but not all. Any other advice with this approach? 3.) using "pdf.options(encoding = 'ISOLatin2') # or utf8, latin1..." did not bring any improvement
– therob
Apr 27 '17 at 8:28
@therob Did you try
usepackage{libertine}
? Can you edit your answer to add your OS+version of programm/Package. It works fiine on my debian 9– nebi
Apr 27 '17 at 15:27
@therob Did you try
usepackage{libertine}
? Can you edit your answer to add your OS+version of programm/Package. It works fiine on my debian 9– nebi
Apr 27 '17 at 15:27
Update: after using sys.setlocale("..") (see above comment) most, but not all characters I mentioned are displayed properly. Funny thing is, that with the same source code all characters worked properly, after using another PC (Windows8.1) in croatia. Maybe there is any croatian package/characterset/keyboardlayout installed, which was not the case in my german test-PC before? I could not figure out why it worked, but it did without further measures from my side....strange...
– therob
May 15 '17 at 12:03
Update: after using sys.setlocale("..") (see above comment) most, but not all characters I mentioned are displayed properly. Funny thing is, that with the same source code all characters worked properly, after using another PC (Windows8.1) in croatia. Maybe there is any croatian package/characterset/keyboardlayout installed, which was not the case in my german test-PC before? I could not figure out why it worked, but it did without further measures from my side....strange...
– therob
May 15 '17 at 12:03
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f366729%2fproblem-with-foreign-characters-some-work-%25c3%25a4%25c3%25b6%25c3%25bc%25c3%259f%25c4%2590%25c3%2598-some-not-%25c4%258c%25c4%2588%25c4%2590%25c4%258e%25c5%25b8-rstudiok%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
This is a question about the R
cat
function, not about TeX.– Thruston
Apr 26 '17 at 7:28
Thanks to your suggestion I have checked with the RStudio console and cat("ČĈĐĎŸ") and print("ČĈĐĎŸ") both produce "CCÐDŸ" out of the box. This differs to the above posted example only in the "Ÿ" which is missing above. Until no I could not find a soluten to properly print these signs inside the console. You suggest to post it to another forum, right (which?)?
– therob
Apr 26 '17 at 8:34