3

This question has helped me in creating a command for my own package (more a list of commands I defined) to force upright lowercase \pi, and so in my package I have the following code: \renewcommand{\pi}{\text{$\mathup{π}$}}

I don't want to include my entire package here because it's huge. So, as a simpler example, when I run the following code (in LuaLaTeX) it works fine and the pi becomes upright:

\documentclass{article}
\usepackage{unicode-math}
\usepackage{amsmath}
\setmathfont{xits-math.otf}    %I use MinionMath-Regular.otf but should work the same
\begin{document}

 \renewcommand{\pi}{\text{$\mathup{π}$}}
 \verb|\pi| = \pi $\pi$       
 %I put both \pi and $\pi$ here just to show that it can work in and out of math mode.

\end{document}

But, it only shows pi as uppercase this for that particular line! If I go to another place in the document and try $\pi$, it reverts to italicised! Since I'd rather not have to type in $\mathup{\pi}$ or $\mathrm{\pi}$ each time, is there any way to force this command as a default instead?

Below is a screenshot of what I would like as default (left) and what I wish to avoid (right):

upright vs italic pi

airatin
  • 303
  • Hello, Could you please modify the example it such way that it includes the "wrong" pi as well, so that we see what exactly is the problem of yours? – yo' Nov 21 '14 at 12:32
  • @tohecz Good idea, I've added a screenshot. – airatin Nov 21 '14 at 12:32
  • Well, your example does not compile. You are missing amsmath package, and you use fonts that are not default in LaTeX. And I still don't understand your point, if I add amsmath and switch to xits-math.otf, I get the same symbol for \pi no matter what I try. – yo' Nov 21 '14 at 12:44
  • Hi, please try the new example. – airatin Nov 21 '14 at 12:56
  • Yes, this example works and prints two upright pi's. Where's the problem? – yo' Nov 21 '14 at 13:03
  • if you always want the upright pi you should put the definition in the preamble. if you have the definition in the body of your document (which is permitted), but it's within a "local group", the definition will go away at the end of the group. (this behavior is why redefinitions are permitted in the body of a document -- sometimes a temporary change is what's wanted.) – barbara beeton Nov 21 '14 at 13:19
  • 1
    I think it's still not clear enough. You are not telling us the whole story. Why would it revert to italic? In any case, using \renewcommand\pi{\text{$\mathup{π}$}} seems quite bad. If it's text mode, it should be text mode (just input π), and if it's math mode, then \renewcommand*\pi{\mathrm{π}} should work after putting that redefinition in the correct place (i.e., not inside a group). – Manuel Nov 21 '14 at 14:03
  • 1
    I'm not sure this is a good way to achieve this. Besides, either all Greek letters are upright or none. If you need an upright pi because you want so denote the constant, then give it a name: \newcommand{\cpi}{\mathrm{\pi}} – egreg Nov 21 '14 at 14:07
  • @tohecz see paragraph below my code. – airatin Nov 21 '14 at 14:16
  • @barbara-beeton I tried this but it doesn't work for me within the document. – airatin Nov 21 '14 at 14:17
  • @Manuel I don't know why it would revert, but if I put the renewcommand in the preamble or anywhere else, using \pi becomes italic. I'll try your definition with the asterisk when I have access to my computer. – airatin Nov 21 '14 at 14:17
  • @egreg I know I can do that, but I want to avoid it. – airatin Nov 21 '14 at 14:17
  • 1
    some package may be setting things up \AtBeginDocument. wrap that around your definition, and put it just before \begin{document} to outwit the other. – barbara beeton Nov 21 '14 at 14:21
  • @airatin That's probably because unicode-math sets the math \AtBeginDocument? Then \AtBeginDocument{\renewcommand*\pi{..}} would put your command after that. In any case, your definition is wrong. – Manuel Nov 21 '14 at 14:21
  • @barbara-beeton Thank you for the suggestion, I'll try this as soon as I get home! – airatin Nov 21 '14 at 14:26
  • @Manuel if you mean the definition is "wrong" because it has text and math mode, it's worked for literally all of my other commands just fine, maybe it's not proper syntax but those commands have worked with zero problems for the last 2 years, up until I want to do upright pi. But I will try your new definition regardless, thanks, I'll update this when I try it at home! – airatin Nov 21 '14 at 14:28
  • @airatin My definition is not necessarily right, it was just a suggestion. But yours is wrong because of that: \text{$..$} has no sense, and you are using it outside math! – Manuel Nov 21 '14 at 14:37
  • @Manuel I have hundreds of commands that use that and I'm sure there was a reason for me to do so when I created them years back. Like I understand maybe for this particular example it might not work, but there was a proper rationale for it when I used it for everything else. I honestly can't remember why I used that format, but it does function properly anyway (for all other commands, except this one). Will using this lead to some sort of malfunction? Because i haven't encountered any yet... – airatin Nov 21 '14 at 14:41

1 Answers1

4

I would follow egreg's comment, all italic, or all upright. In case it's a special occasion, then don't redefine \pi but define another command.

\documentclass{scrartcl}
\usepackage{mathtools}
\usepackage{unicode-math}
\setmainfont{Minion Pro}
\setmonofont{Consolas}[Scale=MatchLowercase]
\setmathfont[Scale=MatchLowercase]{TGPagellaMath}
\AtBeginDocument{\renewcommand*\pi{\mathup{π}}}
\begin{document}
\begin{tabular}{rl}
  \verb|\pi|:            & $\pi$                 \\
  \verb|π|:              & $π$                   \\
  \verb|π| in text mode: & π \emph{π} \textbf{π} \\
\end{tabular}
\end{document}

enter image description here

Manuel
  • 27,118
  • According to ISO standards (80000-2:2009), there are certain greek letters that are upright or italic, depending on context. Hence, it would be easier for me this way. Does this solution not redefine \pi though? Or did you mean not redefining \pi is more recommended / preferred more than following this solution? In either case, will try when I get home, thank you. – airatin Nov 21 '14 at 15:59
  • Yes, this does redefine \pi. I added the version with \pi and π so you can see that you still have italic pi available, in case you don't use it as the constant. – Manuel Nov 21 '14 at 16:20
  • And remember that being usable only in math mode is a feature. What is math should be math, and what is text should be text. – Manuel Nov 21 '14 at 16:36
  • I think I remember why I had it in that format; when I'm jotting down notes in class, it's faster for me to write \xnot instead of $\xnot$ (Or \pi vs $\pi$, etc) when it's in a line of text, hence why I allowed that command to be \text{$..$} and I guess I copied that to all my other commands (regardless of whether I would even use them in text or not!). But when I retype my notes properly at home, I do use proper syntax (I.e. $\pi$), it's just so I can compile and make sense of my notes rushedly typed In class when I get home to retype them. – airatin Nov 21 '14 at 16:43