Strange-looking font in pdf-rendering of LaTeX in RMarkdown file

Hello! I met a strange-looking mathbb font. It is in a pdf generated by R markdown via pandoc.

Specifically, it shows like this graph:
image

instead of the common one \mathbb{R}

I did nothing to the default template of pandoc. It seems the font exists because of default pandoc.

Besides, I have included necessary font package amssymb.

another similar font problem

for mathcal, I want
image
but they are
image
(eucal style)by default, a very frustrating question as they are different with most latex outputs.

What is the problem?

Can you give us a reprex ? I think we need all the YAML , a bit of token text and the code that will show the problems.

Are you using {tinytex} or a full MixTex or Texalive installation?

2 Likes

Ah, here it is. @jrkrideau

---
title: title
author: 
  - Noone

output: 
  bookdown::pdf_document2: 
    keep_tex: yes
    latex_engine: xelatex 
    fig_caption: yes
    number_sections: yes
    toc: yes
    toc_depth: 3
---

This is a $\mathbb{R}$. 

This is mathcal : $\mathcal{ABC}$


when knitted it looked like what I have mentioned.

Besides, I use a full Texlive installation. And I use no pandoc templates.

I wonder if this can show you my problem.

I think I got it. The symbol you want is in the LaTeX package {amsmath} so you need to load it.

I suspect this is very inelegant but try

---
title: The Case of the mysterious *R*
date: today
author: 
  - Noone

output: 
  bookdown::pdf_document2: 
    keep_tex: yes
    latex_engine: xelatex 
    fig_caption: yes
    number_sections: yes
    toc: yes
    toc_depth: 3
header-includes:
    \usepackage{amsmath}
---

This is a $\mathbb{R}$. 

Thank you for your quick reply ! :smile:

However, it does not work on my computer, see

And I did nothing to your code .

You use Rstudio to knit a Rmd file , don't you?

more information is in the output tex file :

% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{article}
\usepackage{amsmath,amssymb}
\usepackage{iftex}
\ifPDFTeX
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math} % this also loads fontspec
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
\usepackage{lmodern}
\ifPDFTeX\else
  % xetex/luatex font selection
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
  \IfFileExists{parskip.sty}{%
    \usepackage{parskip}
  }{% else
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
  \KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\usepackage[margin=1in]{geometry}
\usepackage{longtable,booktabs,array}
\usepackage{calc} % for calculating minipage widths
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
\makesavenoteenv{longtable}
\usepackage{graphicx}
\makeatletter
\newsavebox\pandoc@box
\newcommand*\pandocbounded[1]{% scales image to fit in text height/width
  \sbox\pandoc@box{#1}%
  \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}%
  \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}%
  \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both
  \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}%
  \else\usebox{\pandoc@box}%
  \fi%
}
% Set default figure placement to htbp
\def\fps@figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{5}
\usepackage{amsmath}
\usepackage{bookmark}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same}
\hypersetup{
  pdftitle={The Case of the mysterious R},
  pdfauthor={Noone},
  hidelinks,
  pdfcreator={LaTeX via pandoc}}

\title{The Case of the mysterious \emph{R}}
\author{Noone}
\date{today}

\begin{document}
\maketitle

{
\setcounter{tocdepth}{3}
\tableofcontents
}
This is a \(\mathbb{R}\).

\end{document}

I suppose that the problem comes from this line:

\usepackage{unicode-math}

which is generated by pandoc automatically.
But I don't like to change the original default.latex template.
Do you have any ideas?

I just re-ran my code and I'm back to where you are. I must have done something weird .

However if I do this, is seems to work for me.

---
title: The Case of the mysterious *R*
date: today
author: 
  - Noone

output: 
  bookdown::pdf_document2: 
header-includes:
    \usepackage{amsmath}
---

This is a $\mathbb{R}$. 

First_doc.pdf (101.2 KB)

Likewise, if I run pure LaTeX

---
title: The Case of the mysterious *R*
date: today
author: 
  - Noone

output: 
  bookdown::pdf_document2: 
header-includes:
    \usepackage{amsmath}
\end{document}
---

This is a $\mathbb{R}$. 

I get

So at the moment I am a bit lost but I suspect I have messed up the YAML . I'll poke around but I don't have a good feel for YAML. We can hope someone who does comes along.

I think the problem is coming from the call to the xelatex engine but I have no idea why. Knit with latex_engine: xelatex removed.

---
title: Third Document
author: 
  - No-one
  
output: 
  bookdown::pdf_document2: 
     keep_tex: yes
     fig_caption: yes
     number_sections: yes 
     toc: yes
     toc_depth: 3
     
header-includes:
    \usepackage{amsmath}
---

This is a $\mathbb{R}$. 

Excellent! It works!
The problem is completely due to latex_engine: xelatex command in yaml.
Even if I removed the package amsmath, it would still show the correct version of mathbb \mathbb{R}.

Thanks a lot.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.