3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rmarkdownからknitする際\newcommandを使えるようにする

Posted at

r-wakalangでatusyさんに教えていただいたのでこちらにまとめます。
Rmarkdownで論文を書いている際、こちらのように数式内に下付きの$argmax$を使いたかったのですが、なかなかできませんでした。

教えてくれた答えはシンプルで、本文中に記載するというもの。ただし、
\newcommand{\argmax}{\mathop{\rm arg~max}\limits}
のなかの\rmが古いので\mathrmとするだけ。

解決策

本文中に以下のチャンクを追加する。

cat(sprintf(
  "\\%snewcommand{\\argmax}{\\mathop{\\mathrm arg~max}\\limits}",
  if (knitr::is_latex_output()) "re" else ""
))

数式をかいて

$\argmax_{a} f(x)$

knitをすると、無事に出力できた。
Screen Shot 2020-03-07 at 0.33.37.png

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?