gpt4 book ai didi

latex - R Markdown 与 LaTex 中的 "newcommand"类似的功能?

转载 作者:行者123 更新时间:2023-12-03 23:33:26 24 4
gpt4 key购买 nike

R Markdown 是否具有与 LaTex 的“newcommand”类似的构造?我希望能够定义 \var 之类的东西成为 \mathrm{Var}以避免在数学模式下额外输入。如果不是,人们如何减少在 Markdown 中排版方程式的重复?

最佳答案

我正在使用 bookdown并且需要在 pdf、html 和 docx 输出中始终如一地工作。以上解决方案均不适用于我的情况。这是我确定的hack:

preamble.tex

\usepackage{amsthm}
\DeclareMathOperator*{\argmin}{argmin}
\newcommand{\var}{\mathrm{Var}}

YAML header :
--- 
title: "A Minimal Book Example"
author: "Yihui Xie"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
output:
bookdown::pdf_book:
includes:
in_header: preamble.tex
toc: no
bookdown::word_document2:
reference_docx: template.docx
bookdown::gitbook:
split_by: none
documentclass: article
bibliography: [book.bib, packages.bib]
biblio-style: apalike
link-citations: yes
---

<!--- For HTML Only --->
`r if (!knitr:::is_latex_output()) '
$\\DeclareMathOperator*{\\argmin}{argmin}$
$\\newcommand{\\var}{\\mathrm{Var}}$
'`

<!--- For DOCX Only --->
`r if (!knitr:::is_latex_output() & !knitr:::is_html_output()) '
\\DeclareMathOperator*{\\argmin}{argmin}
\\newcommand{\\var}{\\mathrm{Var}}
'`
# Prerequisites

This is a _sample_ book written in **Markdown**.

关于latex - R Markdown 与 LaTex 中的 "newcommand"类似的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41655383/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com