In R markdown equations, I need to make a curly lower case k, analogous to the curly lower case "l" generated by \ell
. There are a few posts dealing with this, but very LaTex based. I can't find any posts on this issue with a solution for R markdown users who are unfamiliar with the nitty gritty of LaTex. I am using tinytex.

- 787
- 3
- 16
- 32
2 Answers
There are numerous ways to achieve this.
PDF/LaTeX-only
If you need PDF output only you may use a LaTeX package that supports lowercase calligraphic letters in math mode, e.g. dutchcal.
Since this is not tex.stackexchange and you mention that you're not too familiar with Tex, I'm not going too much into detail. Here's a simple example of a PDF rmarkdown project:
Set up a file preamble.tex:
\DeclareMathAlphabet{\mathdutchcal}{U}{dutchcal}{m}{n}
This ensures that dutchcal letters are used in math mode using
\mathdutchcal{<letters>}
.Ensure that the content of preamble.tex is included in the tex file from which the PDF will be generated by setting up the yaml header of your .rmd file accordingly:
--- title: "Mathdutchcal" output: pdf_document: include: in_header: preamble.tex ---
Type lowercase curly letters in math mode:
$$\mathdutchcal{hijkl}$$
Knit to PDF. Result:
As suggested by Ben Bolker, it is convenient to define macros in preamble.tex if you need to type certain curly letters frequently, e.g. with
\newcommand{\curlyk}{\ensuremath\mathdutchcal{k}}
you to get a curly k using \curlyk
.
PDF/LaTeX + HTML/MathJax
As mentioned by Ben Bolker, the above will not work with HTML output because these commands/libraries are not supported by MathJax. Lowercase calligraphic letters in MathJax can be set with \mathscr
. This should also work for PDF output if you compile using xelatex and define a suitable font, e.g. STIXTwoMath in preamble.tex.
Set up preamble.tex:
\setmathfont{STIXTwoMath-Regular.otf}
Set up the yaml header:
--- title: "PDF/LaTeX + HTML/MathJax" output: pdf_document: latex_engine: xelatex include: in_header: preamble.tex ---
Type lowercase curly letters in math mode:
$$\mathscr{hijkl}$$
Knit to PDF or HTML. Results (PDF top, HTML bottom):
Remark. LaTeX packages (dutchcal and stix2-otf) needed for PDF output may not be not installed if you're using tinytex. tinytex should install them when you knit to PDF. If this fails you may install the package manually using a convenience function for the TeX Live Manager, e.g. tinytex::tlmgr_install("dutchcal")
.

- 9,483
- 1
- 14
- 22
-
@BenBolker That's a very helpful suggestion, thanks! I've edited my post. – Martin C. Arnold Aug 12 '21 at 14:49
-
note also that this solution will **not** work (AFAICT) work in mathjax, only in PDF. Getting it to work with Mathjax seems *very* hard. There are some hints that upcoming development versions of Mathjax might have the capabilities to use some other fonts: https://github.com/mathjax/MathJax/issues/2503 – Ben Bolker Aug 12 '21 at 14:53
If you're desperate you might be able to use a Unicode symbol for this. From https://en.wikipedia.org/wiki/Mathematical_Alphanumeric_Symbols, the code for "MATHEMATICAL SCRIPT SMALL K" is 1D4C0. You could cut-and-paste it from the table on Wikipedia or use a compose key (on my Ubuntu system Ctrl-Shift-u + 1D4C0 works): it looks like this — .
I don't know if this will look good in your equations or render properly everywhere but it might be better than nothing. (PDF + LaTeX will definitely look better if that's an option.)

- 211,554
- 25
- 370
- 453