4

I want to define a math symbol \dbar which will display its italic version normally, but display upright when it appears inside \mathrm.

My naïve attempt is something like this

\documentclass{article}
\usepackage{stix2}

\DeclareSymbolFont{stix2-italic}{T1}{stix2}{m}{it}
\DeclareSymbolFont{stix2-upright}{T1}{stix2}{m}{n}
\DeclareMathSymbol{\dbar}{\mathalpha}{stix2-italic}{158}
\DeclareMathSymbol{\updbar}{\mathalpha}{stix2-upright}{158}

\begin{document}
$\dbar \mathrm{\dbar} \updbar$
\end{document}

which outputs:

enter image description here

This is expected since the stix2 package uses LS1 encoding for \mathrm, which has at position 158, while T1 encoding has đ at that position.

Is there a way to define the command \dbar so that it will display as

\DeclareMathSymbol{\dbar}{\mathalpha}{stix2-italic}{158}

normally but display as

\DeclareMathSymbol{\updbar}{\mathalpha}{stix2-upright}{158}

when it appears inside the scope of \mathrm? I do not want to modify the behavior of the stix2 package or of how any other glyph interacts with \mathrm. I would also be interested in hearing solutions involving the unicode-math package.

1 Answer 1

1

There are two different things \mathrm can mean: upright math symbols (such as constants in ISO style) and short lines of text in math mode.

Both Unicode and the T1 encoding have the đ (U+0111) character, as itself or \dj, so you could set \mathrm to either encoding and use \mathrm{\dj}.

However, you are more likely to want to define this command with \text from amsmath or amstext, or similar. A pair of commands for upright and italic math symbols might be:

\newcommand\dstrokeup{\textup{\dj}}
\newcommand\dstrokeit{\textit{\dj}}

If you really do want a command that changes its shape depending on whether you’re in math or text mode, that could be:

\documentclass{article}
\usepackage{iftex}
\usepackage{amsmath}

\iftutex
  \usepackage{fontspec}
\else
  \usepackage[T1]{fontenc}
\fi

\newcommand\dstroke{%
  \ifmmode{\textit{\dj}}%
  \else{\dj}%
  \fi}

\begin{document}
\( \dstroke \text{ is {\dstroke} in text mode.}\)
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .