0

I would like to have a “math upright” command that would automatically conform to the “normal” math typeface of the document. By “normal” math typeface here I mean the typeface that is used if I just type any simple math formula (such as a + b = c) in my document.

That is, in an article, this “math upright” command would behave like \mathrm, but in a beamer presentation (which uses sans serif maths), it wouldn’t behave like \mathrm (which switches to serif).

I am thinking of defining a command \mathup, that I could use as \mathrm, but which would not switch to roman if the rest of the math is not in roman.

I thought about using \DeclareMathAlphabet{\mathup}{OT1}{\familydefault}{m}{n} (as suggested here) but as pointed out by David Carlisle in the comments (if I understood correctly), this is not a good idea because it ties the math “upright” font to the text family default, and not to the normal math typeface as I want.

  • why not just use \mathrm ? but all the standardard ones use OT1, eg \DeclareMathAlphabet {\mathsf}{OT1}{cmss}{m}{n} so that but replacing cmss by \familydefault I guess. – David Carlisle May 09 '20 at 11:10
  • a family, e.g. cmr can be used with a number of encodings (cmr e.g. will work with OT1, T1, LY1 etc), so there is not one encoding that you can detect. OT1 or T1 is normally okay for a math font, if the font can not be used with it, LaTeX will warn you. – Ulrike Fischer May 09 '20 at 14:44
  • @DavidCarlisle The mathup command I dream of means “please now write in math upright and keep the rest (font family, font size…) intact. mathrm differs. I think most uses of mathrm in the wild are semantically wrong in the sense that I suspect that the user means mathup (it’s just that in many cases there is no difference, difference appears if you copy-paste formulæ to a beamer presentation for example). – Olivier Cailloux May 10 '20 at 11:25
  • @DavidCarlisle thanks, that means that an acceptable and easy solution is to use OT1 and hope that the family default is a “standard” one. Any idea for a more robust solution? – Olivier Cailloux May 10 '20 at 11:26
  • @UlrikeFischer I guess then I mean that I would like an automatic way of, given a font, retrieving an encoding compatible with it. – Olivier Cailloux May 10 '20 at 11:28
  • It's a bit had to guess what you want really as the math font setup is essentially independent of the text font setup so you can just make \mathrm be whatever font you want, it's not normal to make the math fonts rely on the external text font setup. If you do not chose OT1 you have to redefine almost all the math symbol declarations which assume OT1 layout (eg upper case Greek in the control code slots of the roman font) that is why lualatex and xelatex default to OT1 math even though they use TU text fonts – David Carlisle May 10 '20 at 11:46
  • "and hope that the family default is a “standard” one. Any idea for a more robust solution? " I don't know what you mean by those comments at all, sorry. – David Carlisle May 10 '20 at 11:47
  • @DavidCarlisle My (perhaps wrong) understanding was derived from this part of the referred post: “One particular problem I am thinking of is when writing in a sans serif-style document (e.g. beamer). In many cases here, your text and math is set in a sans serif font (for screen readability, I guess). Using \mathrm in this case causes the argument to appear in a roman font (with serifs)”. So, in that case at least, it seems that mathrm changes the font that is normally used for math. You are right that I shouldn’t use defaultfamily as that one is for text, not math. – Olivier Cailloux May 10 '20 at 12:14
  • @DavidCarlisle I have tried to clarify my question. Thanks for the comments. – Olivier Cailloux May 10 '20 at 12:34
  • I would say the root cause of the problem is your beamer setup, if you are using sans serif for operator fonts like \log I think you should make \mathrm do the, same (and make \mathsf` do something else, perhaps picking a visually distinct different sans serif font) – David Carlisle May 10 '20 at 12:39
  • @DavidCarlisle Making \mathrm print in sans serif strikes me as an implementation of the advice @UlrikeFischer jokingly gives here: “You can also confuse everyone by defining \mathbf to be light itshape palatino and \mathit a bold Arial.” – Olivier Cailloux May 10 '20 at 12:45
  • 1
    You are free to disagree but that is what I think is the correct thing to do. I can not think of any cases where making \mathrm use a different font to \log will make the math easier to understand. even if that makes \mathrm and \mathsf use the same font that is no worse than \boldmath makin \mathrm and \mathbf use the same font (which is the usual case unless you have an ultra-bold to use for \mathbf) – David Carlisle May 10 '20 at 13:27
  • @DavidCarlisle My concern was simply that the name of the command, mathrm, if I understand correctly, says: switch to math roman (thus, with serif). You are right that typing in math upright should type using the usual math font (only upright), but I don’t think it’s nice to the reader of my code or user of my template that mathrm would not switch to a roman font by second-guessing the user’s intent. Hence my hope for defining another command that does the right thing and has an appropriate name. You may be right that what you propose is a practical solution to the problem, however. – Olivier Cailloux Jun 10 '20 at 07:33
  • 1
    I am not sure I understand the question: you say " the font that is used if I just type any simple math formula (such as a + b = c) in my document." but that would normally be italic? The standard definition of \mathrm is \DeclareSymbolFontAlphabet{\mathrm} {operators} That is, it is not defined as "make a serif roman font" it is defined as "use the same font as used for operators like log" you could define a command with a more semantic name like \DeclareSymbolFontAlphabet{\mathwhatever} {operators} but it would be the same as mathrm (not that that is necessarily a bad thing) – David Carlisle Jun 10 '20 at 07:58
  • Oops. I just edited the question, it should have been “typeface”. Thanks. – Olivier Cailloux Jun 10 '20 at 08:17
  • Independently of the naming problem, I still think \mathrm does not behave in the right way in a Beamer presentation, if what one wants is to type upright but not change the typeface: in Beamer, \mathrm types upright, but also switches typeface. This is the right behavior considering that it satisfies what the command says it does according to its name, but not the right behavior if one wants the thing you say (and I agree) everybody really wants when typing upright (that is, not switch the typeface). – Olivier Cailloux Jun 10 '20 at 08:19
  • @DavidCarlisle Finally, one should distinguish the way a command is defined (its implementation) and its contract (what it declares to its users it will do). I thought that the implicit contract of \mathrm, because of its name, is: make the font roman. Now we can decide that this is a misunderstanding of me (and a poor naming choice) and that its contract really is: type upright and do not touch the typeface. In both cases, there is a problem with beamer presentations when one desires to type upright without changing the typeface. – Olivier Cailloux Jun 10 '20 at 08:26
  • 1
    I'm not a beamer expert but I've always assumed the math font setup is not really usable other than very simple cases unless you use the professionalfonts option, which makes the usual math configuration commands work normally. The default math setup in beamer is extremely non standard and if you are asking about that. best to mention beamer in the question (and, as always provide a complete small test document) – David Carlisle Jun 10 '20 at 08:35
  • I tend to use sansmathfonts for beamer as the roman stuff works better and \mathrm is mapped to \mathsf. – daleif Jun 10 '20 at 08:59
  • The problem is conceptual, not beamer-specific. I used beamer only as a concrete example in the discussion. The problem arises once you’ve decided to use a sans serif family as normal math family. In that case, you have to decide between two interpretations of \mathrm. A) Switch to roman family; B) Use the same font as used for operators (thus, generally, not switching family). Interpretation A) is reasonable considering the name of the command and the example Lamport gives page 51 of The Book. Interpretation B) is reasonable considering that this is probably what the user really wants. – Olivier Cailloux Jun 11 '20 at 09:39
  • Thanks again for this extended discussion, it made me understand much better the issue I face and the choices I have. If you feel like summarizing your point of view in an answer, I’ll accept it; otherwise we can leave it as is, or perhaps close the question as poorly phrased: I would phrase my question much better if I had to ask it now; but I don’t need to as my better understanding replaces the need for an answer. – Olivier Cailloux Jun 11 '20 at 09:43

0 Answers0