# How to enter/render d-hat in emacs and latex export

I want to be able to use d-hat (d with a caret (^) above it) in emacs to indicate an estimate of Cohen's 'd' (an effect size statistic).

How can I enter this in org-mode in a way that it renders within emacs, and also how can I make sure it exports out to latex/PDF?

Thanks

EDIT: Below are a tex file that resulted from a LaTeX export of a one-line org file, with the latex output

% Created 2020-09-17 Thu 16:09
% Intended LaTeX compiler: pdflatex
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\author{U-BRXPS\brett}
\date{\today}
\title{}
\hypersetup{
pdfauthor={U-BRXPS\brett},
pdftitle={},
pdfkeywords={},
pdfsubject={},
pdfcreator={Emacs 26.3 (Org mode 9.1.9)},
pdflang={English}}
\begin{document}

\tableofcontents

This is a d-hat: $$\hat{d}$$
\end{document}

\$ latex test.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (MiKTeX 20.6.29)
entering extended mode
(test.tex
LaTeX2e <2020-02-02> patch level 5
L3 programming layer <2020-07-17>
("C:\Program Files\MiKTeX\tex/latex/base\article.cls"
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
("C:\Program Files\MiKTeX\tex/latex/base\size11.clo"))
("C:\Program Files\MiKTeX\tex/latex/base\inputenc.sty")
("C:\Program Files\MiKTeX\tex/latex/base\fontenc.sty")
("C:\Program Files\MiKTeX\tex/latex/graphics\graphicx.sty"
("C:\Program Files\MiKTeX\tex/latex/graphics\keyval.sty")
("C:\Program Files\MiKTeX\tex/latex/graphics\graphics.sty"
("C:\Program Files\MiKTeX\tex/latex/graphics\trig.sty")
("C:\Program Files\MiKTeX\tex/latex/graphics-cfg\graphics.cfg")
("C:\Program Files\MiKTeX\tex/latex/graphics-def\dvips.def")))
(C:\Users\brett\AppData\Roaming\MiKTeX\tex/latex/grffile\grffile.sty)
y) (C:\Users\brett\AppData\Roaming\MiKTeX\tex/generic/pdfescape\pdfescape.sty)
(C:\Users\brett\AppData\Roaming\MiKTeX\tex/latex/hycolor\hycolor.sty)
(C:\Users\brett\AppData\Roaming\MiKTeX\tex/latex/letltxmacro\letltxmacro.sty)
(C:\Users\brett\AppData\Roaming\MiKTeX\tex/latex/auxhook\auxhook.sty)
(C:\Users\brett\AppData\Roaming\MiKTeX\tex/latex/kvoptions\kvoptions.sty)
("C:\Program Files\MiKTeX\tex/latex/hyperref\pd1enc.def")
(C:\Users\brett\AppData\Roaming\MiKTeX\tex/generic/intcalc\intcalc.sty)
(C:\Users\brett\AppData\Roaming\MiKTeX\tex/generic/etexcmds\etexcmds.sty)
("C:\Program Files\MiKTeX\tex/latex/url\url.sty")
(C:\Users\brett\AppData\Roaming\MiKTeX\tex/generic/bitset\bitset.sty
(C:\Users\brett\AppData\Roaming\MiKTeX\tex/generic/bigintcalc\bigintcalc.sty))
(C:\Users\brett\AppData\Roaming\MiKTeX\tex/generic/atbegshi\atbegshi.sty))
("C:\Program Files\MiKTeX\tex/latex/hyperref\hdvips.def"
("C:\Program Files\MiKTeX\tex/latex/hyperref\pdfmark.def"
(C:\Users\brett\AppData\Roaming\MiKTeX\tex/latex/rerunfilecheck\rerunfilecheck.
sty (C:\Users\brett\AppData\Roaming\MiKTeX\tex/latex/atveryend\atveryend.sty)
(C:\Users\brett\AppData\Roaming\MiKTeX\tex/generic/uniquecounter\uniquecounter.
sty))))
! Undefined control sequence.
<argument> U-BRXPS\brett

l.26  pdflang={English}}

?

• The problem is the backslash in the author name: it is interpreted as the macro \brett by LaTeX which is not defined. Can you use \author{U-BRXPS/brett or some such? – NickD Sep 17 '20 at 12:01

If there is a Unicode d-hat, then using that should take care of it both in the buffer and in the PDF produced through LaTeX (assuming your LaTeX tool chain can handle Unicode, which should be no problem nowadays).

Unfortunately, I can't find such a Unicode character. In the absence of that, I would suggest you use a LaTeX math expression:

$$\hat{d}$$


which will produce a d-hat in the output. But it's not going to look like a d-hat in the buffer, unless you preview the LaTeX fragment with M-x org-latex-fragment (usually bound to C-c C-x C-l) - this is a toggle, so repeating it will eliminate the overlay and show you the LaTeX fragment again. You can preview all the LaTeX fragments in your buffer with C-u C-u C-c C-x C-l and if you want that to happen whenever you open the file, you can add a Local File Variables section at the end of your file:

# Local Variables:
# eval: (org-latex-fragment '(16))
# End:


This last trick is a general Emacs customization trick, applicable generally, not just for Org mode stuff.

See Embedded LaTeX in the manual. In the long run, if you have to do a lot of math, then learning some LaTeX and using this embedding is likely to be a more productive way to produce your documents.

• Thanks, this is great to know. I'm running Emacs from Cygwin on Windows and when I attempt to preview LaTeX fragments, I get the following error: Creating image... org-compile-file: File "/cygdrive/c/Users/brett/AppData/Local/Temp/orgtexG4MJNr.dvi" wasn’t produced. Please adjust ‘dvipng’ part of ‘org-preview-latex-process-alist’.Unable to load color "PaleYellow". Any thoughts? – epicpilgrim Sep 14 '20 at 19:16
• You may be missing dvipng or perhaps some other piece of the LaTeX chain. Can you go from a .tex file to a .dvi file (with latex foo.tex) and then from the dvi file to a png file (with dvipng foo.dvi) on the command line? – NickD Sep 14 '20 at 19:31
• Thanks Nick. I have both those packages. I ran latex/dvipng on another file with no maths in it and it ran fine. However on my maths file, the latex command won't generate the DVI file. It's hard to paste entire output here but it ends with "! Undefined control sequence." right after loading "uniquecounter.sty" and there is no DVI output. This is probably outside the scope of this question but I'm open to keep testing if you have ideas. – epicpilgrim Sep 15 '20 at 20:33
• Maybe you can update your question and add the log that is produced (or at least a few lines around the error) and the tex file that you are trying to process (or again a few lines around whatever causes the error). – NickD Sep 15 '20 at 21:41
• Added to original post – epicpilgrim Sep 17 '20 at 6:13