2

I am trying to define \d as \delta in mathmode, but apparently \d is defined as a dot below and it needs an argument: \d{a} would give an a with a dot below. How can I do this? Here are the packages I am using and wouldn't want to remove because I am not sure what they do exactly

\documentclass[20pt]{report}
\usepackage[utf8]{luainputenc}
\usepackage[skip=8pt,font=footnotesize]{caption}
\usepackage[a4paper, total={6.5in, 9.63in}]{geometry}
\usepackage{microtype}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{graphicx}
\usepackage{float}
\usepackage{amsthm, bm}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{mwe}
\usepackage{physics}
\usepackage{mdframed}
\usepackage{esint}
\usepackage[export]{adjustbox}
\usepackage{bm}
\usepackage{hyperref}
\usepackage[backend=bibtex]{biblatex}
\usepackage[nottoc]{tocbibind}

If I run

\let\d\undefined
\renewcommand{\d}{\delta}

\begin{document}

\begin{align*}
\d
\end{align*}

\end{document

I get ! LaTeX Error: \d undefined.

  • \documentclass[20pt]{report} report does not have a 20pt option. – David Carlisle Jul 19 at 11:44
  • If you want help with an error please show the full error from the log from ! to ?` (see my answer) and post an example document (without any packages not needed to show the error) that produces the error. The code posted does not produce Missing } inserted – David Carlisle Jul 19 at 11:48
  • are you sure you want \usepackage[utf8]{luainputenc} ? It is almost always better to simply use luatex's built in utf-8 unless you have particular need for extra compatibility with inputenc with pdftex. – David Carlisle Jul 19 at 11:56
3

You do not need the \let.

\renewcommand{\d}{\delta}

will redefine \d. However this is almost always a bad idea, any uses of under dots will use \d expecting that it is not redefined.

\documentclass{article}
\DeclareUnicodeCharacter{1ECD}{\d{o}}

\begin{document}

[ọ]
\end{document}

Is supposed to work, so if you redefine \d you need to find every use of \d anywhere and change it to use a different command for an under accent.

The posted code does not produce the missing } error that you state, it produces

! LaTeX Error: Command \d undefined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.24 \renewcommand{\d}
                      {\delta}

as you have undefined \d if you delete the line

\let\d\undefined

then it runs without error.

  • Is there any way using \ifmmode test? – Marian G. Jul 19 at 11:51
  • @MarianG. You could but not redefining standard latex commands would be my strong recommendation. – David Carlisle Jul 19 at 11:54
  • I added my attempt below. Feel free to downvote my answer if it is bad. – Marian G. Jul 19 at 12:08
  • @DavidCarlisle it is still the same error if I remove \let\d\undefined – MBolin Jul 19 at 12:19
  • The code posted produces no error. If you posted a code that produces the missing } error then someone could debug it. – David Carlisle Jul 19 at 12:33
1

Update (according to comments of D. Carlisle)

\documentclass{article}
\usepackage{amsmath}

\let\oldd\d

\protected\def\d{%
    \ifmmode\delta\else\expandafter\oldd\fi}

\begin{document}
\parindent0pt


text mode: \d a
\bigskip

math mode: $\delta\frac{1}{2}$, $\begin{array}{c}\d\gamma\end{array}$, $\d^2$
\end{document}

Original attempt

I'm not an expert, but it seems that the following approach also work. It would be very nice if someone discuss in more detail if the presented attempt is safe.

\documentclass{article}
\usepackage{amsmath}

\let\oldd\d

\def\d#1{%
    \ifmmode\delta\else\oldd{#1}\fi
    \ifmmode#1\fi}

\begin{document}
\parindent0pt


text mode: \d a
\bigskip

math mode: $\d^2-4\text{\d a}$, $\d$
\end{document}

enter image description here

  • This doesn't work for me. If I write $\d$ I get ! Missing $ inserted. – MBolin Jul 19 at 12:21
  • @MBolin: Thank you for your feedback. Corrected. – Marian G. Jul 19 at 12:28
  • 1
    This fails $\begin{array}{c} \d \gamma \end{array} $ This gives no error but makes nonsensical output $ \d \frac{1}{2} $ basically the redefinition breaks latex, it is not recommended. – David Carlisle Jul 19 at 12:38
  • 1
    if you want to do this then \protected\def\d{\ifmmode\delta\else\expandafter\oldd\fi} but it is still not recommended. – David Carlisle Jul 19 at 13:28
  • @DavidCarlisle: You are right. Thank you for your valuable comments. I added an update to my bad answer. – Marian G. Jul 19 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.