Writing greek letters in rmarkdown to docx (newcommand for docx) - r-markdown

I am trying to write none-italic "uL" (microliters) in R markdown with the letter "mu".
It is no problem creating a newcommand for PDF that replaces "\microliters" with "uL".
newcommand{\microliters}{\textmu L}
This (of course?) does not work when knitting to docx. As a workaround, I can live with \microliters being replaced by a "uL" with a regular "u" - in stead of "mu".
But how can I create a docx "newcommand", that does that?

I'm not sure about "newcommand", but this works when converting from rmarkdown to docx:
µl
or
μ

I finally got a solution - not sure if any of the packages are mandatory, so I have included them all:
---
title: "Concentrationmeasurements"
author: "Christian Aa. Olesen"
date: "April 29, 2018"
output:
word_document: default
pdf_document:
latex_engine: pdflatex
header-includes:
- \usepackage{float}
- \floatplacement{figure}{H}
- \usepackage{setspace}
- \doublespacing
- \usepackage{lipsum}
- \usepackage{multirow}
- \usepackage[table,xcdraw]{xcolor}
- \usepackage{lineno}
- \linenumbers
- \usepackage{rotating}
- \usepackage{tikz}
- \usepackage{enumitem}
- \usepackage{blindtext}
- \usepackage{textcomp}
- \usepackage{refstyle}
- \usepackage{graphicx}
- \usepackage[font=small,labelfont=bf]{caption}
- \usepackage{tabularx}
- \usepackage[page]{appendix}
- \usepackage{amsmath}
- \usepackage{amsfonts}
- \usepackage{amssymb}
- \usepackage{hyperref}
- \usepackage{textcomp}
- \usepackage{graphicx}
- \usepackage{amsmath}
- \usepackage{xspace}
- \newcommand{\rtmark}{\textsuperscript{\textregistered}\xspace}
- \usepackage{multirow}
- \usepackage{float}
---
```{r,echo=FALSE, results='asis'}
doc.type <- knitr::opts_knit$get('rmarkdown.pandoc.to')
if (doc.type == "docx") cat(paste("\\newcommand{\\microliters}{\\mathrm{\\mu l}}")) else cat(paste("\\newcommand{\\microliters}{\\textrm{\\textmu l}}","\n"))
```

Related

How to cite different authors with the same last name with Bibtex

I am using rmarkdown with bibtex citation package, but don't know how to handle the citation of different authors with the same last name. I found the post https://tex.stackexchange.com/questions/287970/how-to-cite-two-different-authors-with-the-same-surname-in-bibtex, but this does not work with rmarkdown. Any help would be appreciated.
---
title: "Paper"
thanks:
author: |
| \normalfont myself
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
pdf_document:
number_sections: true
citation_package: natbib
fig_caption: true
fig_height: 4.5
fig_width: 8
link-citations: yes
toc: false
bibliography: /Users/jj/Documents/ch3/references02.bib
biblio-style: apalike
in_header: preamble.tex
keep_tex: yes
fontsize: 12pt
linestretch: 1.2
subparagraph: true
number_sections: true
geometry: margin=1in
header-includes:
- \usepackage{amsmath}
- \usepackage{amsthm}
- \usepackage{bbm}
- \numberwithin{equation}{section}
- \usepackage{makecell}
- \usepackage{indentfirst}
- \usepackage{geometry}
- \usepackage{graphicx}
- \usepackage{tikz}
- \usepackage{verbatim}
- \usepackage{chronosys}
- \usepackage{stackengine}
- \usepackage{booktabs, colortbl, xcolor}
- \usepackage{babel}
- \usetikzlibrary{arrows.meta,calc}
- \usepackage[font=small]{caption}
- \usepackage{adjustbox}
- \usepackage{tabularx}
- \usepackage{pgfplots}
- \pgfplotsset{compat=1.7}
- \usepackage[makeroom]{cancel}
- \usetikzlibrary{arrows,decorations.markings}
- \usetikzlibrary{intersections}
- \usepackage[nottoc]{tocbibind}
- \newtheorem{prop}{Proposition}
- \newtheorem{definition}{Definition}
- \newtheorem{algorithem}{Algorithm}
- \usepackage[T1]{fontenc}
- \usepackage{tabularx,ragged2e,booktabs,caption}
- \newenvironment{rcases}
{\left.\begin{aligned}}
{\end{aligned}\right\rbrace}
- \renewcommand{\refname}{References}
- \UseRawInputEncoding
- \usepackage[utf8]{inputenc}
- \usepackage{hyperref}
- \hypersetup{
colorlinks=true,
linkcolor=black,
filecolor=blue,
citecolor = blue,
urlcolor=blue,
}
- \usepackage{subcaption}
- \usepackage[font=small,labelfont=bf]{caption}
- \usepackage{float}
- \usepackage{flafter}
- \floatstyle{plaintop}
- \restylefloat{table}
- \setlength{\parindent}{2.5em}
- \setlength{\parskip}{0em}
- \usepackage{adjustbox}
- \usepackage[style=english]{csquotes}
- \usepackage[nameinlink,capitalize,noabbrev]{cleveref}
- \creflabelformat{equation}{#2\textup{(\textcolor{red}{#1})}#3}
- \creflabelformat{figure}{#2\textcolor{red}{#1}#3}
- \creflabelformat{table}{#2\textcolor{red}{#1}#3}
- \creflabelformat{section}{#2\textcolor{red}{#1}#3}
- \usepackage[toc,page]{appendix}
- \usepackage{rotating}
- \usepackage{accents}
- \newcommand*{\dt}[1]{%
- \accentset{\mbox{\large\bfseries .}}{#1}}
- \DeclareMathOperator{\Tr}{Tr}
- \usepackage{cleveref}
---
references02.bib file is the following:
#incollection{chang2003,
author="Chang, Ha-Joon",
editor="Ha-Joon Chang",
title="Trade and Industrial Policy Issues",
bookTitle="Rethinking Development Economics",
year="2003",
publisher="Anthem Press",
pages="257-276"
}
#book{sjchang2003,
place={Cambridge},
title={Financial Crisis and Transformation of Korean Business Groups: The Rise and Fall of Chaebols},
DOI={10.1017/CBO9780511510861},
publisher={Cambridge University Press},
author={Chang, Sea-Jin},
year={2003}
}
The text would be:
\cite{chang2003} and \cite{sjchang2003} said different things, blah blah...

Problem with ligatures in Rmarkdown / bookdown pdf output

In my Rmarkdown project, I'm having trouble in correctly exporting ligatures in PDF file.
font-config.tex file -
\usepackage{fontspec}
\setmainfont{Noto Sans}
YAML front-matter in Rmd file -
---
title: "test"
author: "author"
date: "22/02/2021"
output:
pdf_document:
latex_engine: xelatex
includes:
in_header: font-config.tex
---
The following text is in hindi language.
गुरु
Output shown in PDF -
Output expected -
The Nakula font is correctly displayed, but it does not have bold-face type font.
The Noto Sans font I'm using works fine in html output, but have problem with ligature in PDF output.
I tried, the pandoc documentation and other similar questions on stackoverflow and tex.stackexchange, but no luck.
I'm new to TeX, and hopefully it has a very simple solution.
This may work for you, following the information given here:
---
title: "Hindi"
author: "bttomio"
output:
pdf_document:
latex_engine: xelatex
header-includes:
- \usepackage{fontspec}
- \setmainfont{Noto Sans}
- \usepackage{polyglossia}
- \setdefaultlanguage{hindi}
- \setotherlanguage{english}
- \newfontfamily\devanagarifont[Scale=MatchUppercase]{Nakula}
- \newfontfamily\devtransl[Mapping=DevRom]{Times New Roman}
---
The following text is in hindi language.
गुरु
-output

codeclimate validate-config Error

Am new to code climate and am facing this error when i run my github project on codeclimate.
codeclimate validate-config
ERROR: Unable to parse: (<unknown>): found unexpected end of stream while scanning a quoted scalar at line 23 column 5
Below is my .codeclimate.yml file :
---
machine:
environment:
CODECLIMATE_REPO_TOKEN: ab24b326dac817e772c5246823b67af66e2358e51134c33e20aaf7fb228088b0
engines:
duplication:
enabled: false
config:
languages:
- python
fixme:
enabled: true
pep8:
enabled: true
radon:
enabled: true
ratings:
paths:
- "**.py"
exclude_paths:
- "docs/*"
- "examples/*
-*api/songs/models*
-*/site-packages/*
-*markupsafe/*
-*psycopg2/*
-*six.py*
-*sqlalchemy/*
-*werkzeug/*
-*stringprep.py*
-*uuid.py*
-*ctypes/*
-*decimal.py*
-*encodings/*
-*hmac.py*
-*asyncio/*
-*concurrent/*
-*multiprocessing/*
-*mimetypes.py*
-*numbers.py*
-*pydoc.py*
-*http/*
-*app/api/user/__init__.py*
-*app/api/request/__init__.py*
-*app/api/__init__.py*
-*app/__init__.py*
-*app/config.py*
-*app/model/*
-*test/*
-*html/*
-*_bootlocale.py*
-*typing.py*
The line line 23 which is in the error message is as below in the file above:
- "examples/*
What should i do to correct this?
The problem with that line is it's missing the closing quotation mark. However, all of the exclude_paths patterns will need to be enclosed in quotes; i.e. the config should look like this:
---
machine:
environment:
CODECLIMATE_REPO_TOKEN: ab24b326dac817e772c5246823b67af66e2358e51134c33e20aaf7fb228088b0
engines:
duplication:
enabled: false
config:
languages:
- python
fixme:
enabled: true
pep8:
enabled: true
radon:
enabled: true
ratings:
paths:
- "**.py"
exclude_paths:
- "docs/*"
- "examples/*"
- "*api/songs/models*"
- "*/site-packages/*"
- "*markupsafe/*"
- "*psycopg2/*"
- "*six.py*"
- "*sqlalchemy/*"
- "*werkzeug/*"
- "*stringprep.py*"
- "*uuid.py*"
- "*ctypes/*"
- "*decimal.py*"
- "*encodings/*"
- "*hmac.py*"
- "*asyncio/*"
- "*concurrent/*"
- "*multiprocessing/*"
- "*mimetypes.py*"
- "*numbers.py*"
- "*pydoc.py*"
- "*http/*"
- "*app/api/user/__init__.py*"
- "*app/api/request/__init__.py*"
- "*app/api/__init__.py*"
- "*app/__init__.py*"
- "*app/config.py*"
- "*app/model/*"
- "*test/*"
- "*html/*"
- "*_bootlocale.py*"
- "*typing.py*"
Note: You'll still see some deprecation warnings because you're using the old .codeclimate.yml format. There is information about converting from the old format to version 2 in the CodeClimate docs:
https://docs.codeclimate.com/docs/advanced-configuration#section-analysis-configuration-versions

How to add an index to a PDF rendered from an Rmarkdown document using Rstudio on Windows?

The example document below is intended to include an index after the appendix. In a Sweave document, Rstudio would run a shell escape command to create the index .idx file, but I've not been able to find a way to do this for an Rmarkdown document. Is there a simple header command I'm missing?
---
title: "Untitled"
output:
pdf_document:
toc: yes
header-includes:
- \usepackage{makeidx}
- \makeindex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# R Markdown
This is an \index{R Markdown} R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
# Appendix - A
End of the document
\printindex
I've tried this from both the Knit button and using:
rmarkdown::render(rmd.file, output_format = "pdf_document", clean = FALSE)
I'm looking for a solution that can run as part of an automated process.
UPDATE:
I was able to get the index to work by changing the output type to bookdown::pdf_document2. The additional latex packages were required for a combination of indexing, cross referencing, and formatting.
---
title: "Untitled"
output:
bookdown::pdf_document2:
toc: no
geometry: margin=0.8in
header-includes:
- \usepackage{attachfile2}
- \usepackage{booktabs}
- \usepackage{caption}
- \usepackage{float}
- \usepackage[utf8]{inputenc}
- \usepackage{makeidx}
- \makeindex
- \usepackage{multirow}
- \usepackage{setspace}
- \usepackage{relsize}
- \usepackage[table]{xcolor}
- \setcounter{tocdepth}{5}
- \setcounter{secnumdepth}{0}
- \hypersetup{unicode=true,pdfusetitle,bookmarks=true,bookmarksnumbered=true,bookmarksopen=true,bookmarksopenlevel=2,breaklinks=false,backref=false,colorlinks=true,linkcolor=blue}
---
While this would work when manually pushing the create PDF button, the call to rmarkdown::render() still does not process the indexing.

Unclassifiable statement and Fatal Error: Invalid character '$' at (1)

I am encountering errors when I try to compile an old Fortran code. I don't wish to change the program, but just to be able to run it.
I tried Simply Fortran and I am attempting to build the file, but I get these errors:
==============================================================================
Generating Makefile... Okay
==============================================================================
Compiling .\tmod9502.f
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.\tmod9502.f:97:6:
INCLUDE TMCOMMON.FOR
1
Error: Unclassifiable statement at (1)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.\tmod9502.f:98:25:
CHARACTER*15 INPUTS$,SUBCAT$,PARAMS$,OUTPUT$
1
Fatal Error: Invalid character '$' at (1). Use '-fdollar-ok' to allow it as an extension
compilation terminated.
Error(E42): Last command making (build\tmod9502.o) returned a bad status
Error(E02): Make execution terminated
Based on this initial bit of code:
INCLUDE TMCOMMON.FOR
CHARACTER*15 INPUTS$,SUBCAT$,PARAMS$,OUTPUT$