Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3-line mathmode setting for upright indices wont work anymore #57

Closed
Pratched opened this issue Mar 14, 2021 · 9 comments
Closed

3-line mathmode setting for upright indices wont work anymore #57

Pratched opened this issue Mar 14, 2021 · 9 comments

Comments

@Pratched
Copy link

Pratched commented Mar 14, 2021

I noticed, that this probably known "setting" for upright indices in mathmode without a need for single \mathrm{} every time, no longer works with tudscr. I havnt used tudscr for a while, but it worked at least 1-2 yrs ago.

\mathcode`\.="8000
\begingroup\lccode`~=`.
\lowercase{\endgroup\def~}#1{\mathrm{#1}}

Furthermore is it working when using scr itself or even article, as following MWE might prove.

\documentclass{tudscrbook}
%\documentclass{scrbook}
%\documentclass{article}
\mathcode`\.="8000
\begingroup\lccode`~=`.
\lowercase{\endgroup\def~}#1{\mathrm{#1}}
\begin{document}
$a_.b$\\
$a_.{bv}$\\
$a_b$
\end{document}

In case it is not as common as I thought, I cant remember where I first found this "setting", but it is described here as well.

@mrpiggi
Copy link
Member

mrpiggi commented Mar 15, 2021

This is related to the usage of package mathastext in order to use Open Sans for math mode. The named package defines a large amount of tokens including . to be active.

I would suggest a slightly different approach for creating upright subscripts, inspired by https://tex.stackexchange.com/a/496613
With \uprightsubscripts and \italicsubscripts you can define, whether you want to use upright or italic subscripts as default. In order to get the contrary output, you only have to use $x_|subscript|$ instead of the normal syntax $x_{subscript}$.

\documentclass{tudscrartcl}

\makeatletter
\newcommand*\mathsub@upright[1]{\sb{\mathrm{#1}}}
\newcommand*\mathsub@italic[1]{\sb{\mathit{#1}}}
\newcommand*\mathsub@default{}
\newcommand*\mathsub@variant{}
\begingroup%
  \catcode`\_=13%
  \gdef_{%
    \kernel@ifnextchar(%)
      {\mathsub@variant}%
      {\mathsub@default}%
  }%
  \gdef_{\@ifnextchar|\mathsub@variant\mathsub@default}%
\endgroup%
\AtBeginDocument{%
  % default setting if \[upright|italic]subscripts wasn't invoked so far
  \ifx\mathsub@variant\@empty\italicsubscripts\fi%
  \mathcode`_="8000%
  \catcode`\_=12%
}
\newcommand*\uprightsubscripts{
  \let\mathsub@default\mathsub@upright%
  \def\mathsub@variant(##1){\mathsub@italic{##1}}%
  \def\mathsub@variant|##1|{\mathsub@italic{##1}}%
}
\newcommand*\italicsubscripts{%
  \let\mathsub@default\mathsub@italic%
  \def\mathsub@variant(##1){\mathsub@upright{##1}}%
  \def\mathsub@variant|##1|{\mathsub@upright{##1}}%
}
\makeatother


\begin{document}
$a_(b)$
$a_(bv)$
$a_|b|$
$a_|bv|$
$a_b$
$x_{default}$
$x_(variant)$
$x_|variant|$

\uprightsubscripts
$a_(b)$
$a_(bv)$
$a_|b|$
$a_|bv|$
$a_b$
$x_{default}$
$x_(variant)$
$x_|variant|$

\italicsubscripts
$a_(b)$
$a_(bv)$
$a_|b|$
$a_|bv|$
$a_b$
$x_{default}$
$x_(variant)$
$x_|variant|$
\end{document}

EDIT: Regarding #57 (comment), changed from $x_|variant|$ to $x_(variant)$

@mrpiggi mrpiggi added this to the v2.07 milestone Mar 15, 2021
@mrpiggi mrpiggi self-assigned this Mar 15, 2021
@keinstein
Copy link

keinstein commented Mar 15, 2021 via email

@mrpiggi
Copy link
Member

mrpiggi commented Mar 15, 2021

Well, the argument is not optional but a variant for the mandatory one. Nevertheless, asymmetric borders is a point, changed from $x_|variant|$ to $x_(variant)$

@Pratched
Copy link
Author

Ah alright. Im not going to pretend, I fully understand whats been done neither in my original snippets or your solution, but many thanks.

@mrpiggi
Copy link
Member

mrpiggi commented Mar 15, 2021

Leave open as potential feature for a future release

@mrpiggi mrpiggi reopened this Mar 15, 2021
@Pratched
Copy link
Author

That would be great. Especially since upright indices are expected most of the time throughout TUD.
One last question though, since Ive been too quick in closing anyway:

This does not seem to work when using predefined symbols with glossaries when using said syumbols with \gls{}? Might there be a quick fix for that as well?

@mrpiggi
Copy link
Member

mrpiggi commented Mar 15, 2021

please open a new issue and provide a mwe

@mrpiggi
Copy link
Member

mrpiggi commented Mar 19, 2021

According to https://tex.stackexchange.com/q/62705 and https://tex.stackexchange.com/q/245880 a slightly different and (hopefully) more robust solution considering text mode as well

\documentclass{tudscrartcl}
\usepackage[T1]{fontenc}

\makeatletter
\newcommand*\mathsub@upright[1]{\sb{\mathrm{#1}}}
\newcommand*\mathsub@italic[1]{\sb{\mathit{#1}}}
\newcommand*\mathsub@default{}
\newcommand*\mathsub@variant{}
\newcommand*\uprightsubscripts{
  \let\mathsub@default\mathsub@upright%
  \def\mathsub@variant(##1){\mathsub@italic{##1}}%
}
\newcommand*\italicsubscripts{%
  \let\mathsub@default\mathsub@italic%
  \def\mathsub@variant(##1){\mathsub@upright{##1}}%
}
\newcommand*\mathsub@choice{%
  \kernel@ifnextchar(%)
    {\mathsub@variant}%
    {\mathsub@default}%
}
\catcode`\_=\active%
\gdef_{\relax\ifmmode\expandafter\mathsub@choice\else\textunderscore\fi}%
\AtBeginDocument{%
  % ensure right catcodes
  \catcode`\_=\active%
  \mathcode`_="8000%
  % default setting if \[upright|italic]subscripts wasn't invoked so far
  \ifx\mathsub@variant\@empty\italicsubscripts\fi%
}
\makeatother

\usepackage{hyperref}
\begin{document}
\begin{figure}
  \caption{$x_y$}
  \label{z}
\end{figure}

bar_{foo}

bar_(foo)

$bar_{foo}$

$bar_(foo)$

\bigskip

$a_(b)$
$a_(bv)$
$a_b$
$x_{default}$
$x_(variant)$

\uprightsubscripts
$a_(b)$
$a_(bv)$
$a_b$
$x_{default}$
$x_(variant)$

\italicsubscripts
$a_(b)$
$a_(bv)$
$a_b$
$x_{default}$
$x_(variant)$
\end{document}

@mrpiggi
Copy link
Member

mrpiggi commented Mar 25, 2021

Final solution can be found here: #58 (comment)

@mrpiggi mrpiggi closed this as completed Mar 25, 2021
@mrpiggi mrpiggi removed their assignment Mar 25, 2021
@mrpiggi mrpiggi removed this from the v2.07 milestone Mar 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants