1

So I have been trying to make a command to display my very particular notation for restriction, but I believe parts of it involve text commands and other parts involve math commands, I thought I had properly considered each but I still get errors about the parameters not being in math mode:

The command:

\usepackage{amssymb}
\usepackage{graphics}
\DeclareRobustCommand{\rest}[1]{\text{\raisebox{-5.8pt}{\scalebox{1}[2.6]{$\upharpoonright$}_{\ensuremath{#1}}}\hspace{-7pt}}}

Would work but I still get error messages about lacking the $ $ in the arguments (even if I do put them in there).

The result that I wanted to get from this command was to be the same as if I wrote:

$$\pi\raisebox{-5.8pt}{\scalebox{1}[2.6]{$\upharpoonright$}}_{H}\hspace{-7pt}(a)$$

when i write

$$\pi\rest{H}(a)$$

And that should look like:

enter image description here

mrCarnivore
  • 1,505
Felipe Dilho
  • 355
  • 1
  • 7
  • May I ask: what is the reason for using \text in that definition of \rest? – daleif May 09 '23 at 07:55
  • \scalebox{1}[2.6]{$\upharpoonright$}_{ has _in text, the whole of scalebox shoud be in $...$ and do not use \enuremath here – David Carlisle May 09 '23 at 08:08
  • @daleif I believe that those box (\scalebox,,\raisebox) commands are for text enviroments, I may be wrong but that would explain why I need to put the $...$ inside \scalebox for it to work. – Felipe Dilho May 09 '23 at 08:12
  • @DavidCarlisle you mean \ensuremath ? – Felipe Dilho May 09 '23 at 08:13
  • sorry yes, once you have fixed the $ you will be in math so no need to use \ensuremath to test for math. Note also you should not use $$ in latex – David Carlisle May 09 '23 at 08:16
  • "but that would explain why I need to put the $...$ inside \scalebox for it to work." no you always need $ in \scalebox not just in \text – David Carlisle May 09 '23 at 08:17
  • @DavidCarlisle I don't really wanna argue here about this, but is there really a concrete reason why I should use \[ \] instead of $$ $$ beyond "its (supossedly) deprecated"? – Felipe Dilho May 09 '23 at 08:19
  • 1
    It is not "deprecated" that would imply it was once supported but now not, but $$ has never been documented as latex syntax, https://tex.stackexchange.com/questions/503/why-is-preferable-to/69854#69854 or more recently https://tex.stackexchange.com/a/684210/1090 – David Carlisle May 09 '23 at 08:24
  • It is a part of TeX though, and for unumbered equations it has a very nice complementary sintax relation with $...$, these types of dicussions seem like those in which someone considers a sin to code in C++ like C, if it works, and doesn't break anything, I don't see the probem. – Felipe Dilho May 09 '23 at 08:31
  • 1
    @FelipeDilho It does break things. – egreg May 09 '23 at 08:39
  • \scalebox and \raisebox can be used everywhere, it is just that it always typesets its argument as text – daleif May 09 '23 at 08:56

2 Answers2

6

You should use no explicit dimensions, so the command can work at different sizes and different fonts.

I also add a *-version that copes with the problem of a “deep” function argument.

\documentclass{article}
\usepackage{mathtools,amssymb}
\usepackage{graphicx}

\NewDocumentCommand{\rest}{sm}{% \vcenter{\hbox{\scalebox{1}[2.6]{$\upharpoonright$}}}% \IfBooleanTF{#1}{% _{!#2}% }{% _{\mathrlap{!#2}},% }% }

\begin{document}

[ \pi\rest{H}(a) \qquad \pi\rest*{H}\biggl(,\sum_{k=1}^n a_k\biggr) ]

\end{document}

Explanation: \vcenter will center the object with respect to the formula axis. With \mathrlap the subscript is considered to have zero width, but that doesn't happen with \rest*.

enter image description here

egreg
  • 1,121,712
2

You do not need any $ at all in the command:

\documentclass{article}

\usepackage{amssymb} \usepackage{graphics}

\DeclareRobustCommand{\rest}[1]{\raisebox{-5.8pt}{\scalebox{1}[2.6]{$\upharpoonright$}}_{#1}\hspace{-7pt}}

\begin{document} $\pi\raisebox{-5.8pt}{\scalebox{1}[2.6]{$\upharpoonright$}}_{H}\hspace{-7pt}(a)$

$\pi\rest{H}(a)$

\end{document}

I also removed the \pi and (a) from the command since it seems you want them completely variable and put them before and after the commmand when you use it by your example in the question.

mrCarnivore
  • 1,505
  • Thank you very much!!! So only the parameter of \scalebox must contain the $...$, huh, functionally would that mean that \scalebox: \elementoftextmode -> \elementofmathmode ? – Felipe Dilho May 09 '23 at 08:26
  • Basicly the content of your command is placed instead of its name in the text. You already put $$ on the outside. If you put $ again you are going out of maths mode and therefore they are missing and you get the error message you had been getting. – mrCarnivore May 09 '23 at 08:28