LoginSignup
1
0

MathJaxで \bm を使う

Last updated at Posted at 2023-08-16

$\def\bm#1{{\boldsymbol #1}}$
MathJaxはデフォルトで \bm に対応していないので、\bf を使って $\bf a$ とするか、\boldsymbol を使って $\boldsymbol a$ とする場合が多い。

やりたいこと

以下のコードで

\bm y = \bm X \bm w

以下を出力する。

$$
\bm y = \bm X \bm w
$$

方法1

MathJaxを埋め込んだページの任意の箇所 (個人的にはできるだけ上部がよいと思う) に以下のコマンドを埋め込む。

\def\bm#1{{\boldsymbol #1}}

方法2

MathJaxを埋め込んだサイトの<head>タグ内の、MathJax埋め込みに用いている<script>内に、以下のコードを適切に追記する。

tex: {
    macros: {
        bm: ["\\boldsymbol{#1}", 1],
    },
},

たとえば以下のようにするといい感じになる。

<script>
    MathJax = {
        tex: {
            inlineMath: [                 // start/end delimiter pairs for in-line math
                ['$', '$'],
                ['\\(', '\\)'],
            ],
            displayMath: [                // start/end delimiter pairs for display math
                ['$$', '$$'],
                ['\\[', '\\]']
            ],
            processEscapes: true,
            macros: {
                bm: ["\\boldsymbol{#1}", 1],
            },
        }
    };
</script>

免責並びに参考文献

本記事を適用したこと・適用できないことによって生じる損害には一切責任を負うことができません。予めご了承ください。

  1. https://docs.mathjax.org/en/latest/options/input/tex.html
  2. https://docs.mathjax.org/en/latest/input/tex/extensions/newcommand.html
1
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
1
0