0

Is is possible to allow consecutive subscripts/superscripts? I’m discovering the joy of typing UTF-8 characters easily from my keyboard (thanks bépo) and I’d love to be able to type x²ˣ instead of x^{2x}, however if I define my characters like:

\newunicodechar{²}{^2}
\newunicodechar{ˣ}{^x}

then LaTeX would complain about the fact that I have two consecutive superscripts. Is there a workaround?

MWE:

\documentclass{article}

\usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{amsmath} \usepackage{amsfonts}

\usepackage{newunicodechar} \newunicodechar{²}{^2} \newunicodechar{ˣ}{^x} \begin{document}

$x²ˣ > 0$

\end{document}

tobiasBora
  • 8,684
  • 1
    https://tex.stackexchange.com/a/618428/250119 yes if you try really hard. – user202729 Apr 12 '23 at 16:06
  • you could define ² like ' to look ahead so x²ˣ is x^{2x} but I woudn't – David Carlisle Apr 12 '23 at 16:06
  • @user202729 thanks but it does not explain how to do in with pdflatex, which is the point of this question. – tobiasBora Apr 12 '23 at 16:11
  • 1
    but my answer there works for PDFLaTeX read carefully... – user202729 Apr 12 '23 at 16:12
  • ohh good point, thanks a lot, I stopped reading when I saw A similar algorithm is possible in PDFTeX, but it needs some adaptation because each Unicode character (in UTF-8) corresponds to multiple tokens in PDFTeX. (not included)… but seems like this is an outdated statement. This works great indeed. Is is the solution you had in mind @DavidCarlisle a simpler approach is possible? – tobiasBora Apr 12 '23 at 16:17
  • 1
    as I say I wouldn't use superscript characters at all. Perhaps a simple \newunicodechar{ˣ}{{}^x} is good enough, it depends what you want ²ˣ to mean – David Carlisle Apr 12 '23 at 16:23
  • @tobiasBora Okay fixed that one. // Not that I'm aware of, but just copy that 270 lines into your preamble and forget about it. – user202729 Apr 12 '23 at 16:23
  • I've been intending to wrap the thing into a package but never get the effort to actually release it. // Also TeX is a really low-level language with a very limited set of "built-in functions", so implementation of anything nontrivial must necessarily be long. – user202729 Apr 12 '23 at 16:27
  • Oh ok, I thought you had a simple fix @DavidCarlisle. So I’m curious, would you also recommend x^\prime instead of x'? :-P To me, x⁰ ⊕ x¹ is easier to read and faster to type than x^0 \oplus x^1. – tobiasBora Apr 12 '23 at 16:44
  • @user202729 Ok thanks a lot! – tobiasBora Apr 12 '23 at 16:45
  • I wouldn't even know how to type :-) but that superscript mathematically a 1, I'd want to find it when searching for 1 in my editor. this does not apply for \prime as that is never used full size – David Carlisle Apr 12 '23 at 16:46
  • "Oh ok, I thought you had a simple fix" well it is simple, it just depends whether you consider it a fix – David Carlisle Apr 12 '23 at 16:50
  • @DavidCarlisle hum, it might just mean that we should improve our editors and keyboards to better handle utf-8 characters :-P Ahah, then thanks for the "fix" ;-) – tobiasBora Apr 12 '23 at 16:51
  • specifically x{}^2{}^x isn't an error and may (or may not) be mathematically better than x^{2x} depending if it is a single superscript or a list of superscript indexes like tensor notation – David Carlisle Apr 12 '23 at 16:55
  • Ohh sorry I did not realized that \newunicodechar{ˣ}{{}^x} would not produce an error, my mistake. So the formating is slightly different as it adds a small space, but it’s indeed an interesting simple solution. Note however that it would not handle correctly stuff like 2ᵃᵇ_{c} as c would be below the b and not the a. – tobiasBora Apr 12 '23 at 16:58
  • sorry but you are using symbols based on the look and not on the meaning. Math can not be represented simply by a chain of utf8 chars, as it is two dimensional and uses font variants. If you try to make the input more simple and visually pleasing you loose formatting options. – Ulrike Fischer Apr 12 '23 at 18:50
  • @UlrikeFischer I don’t understand why using β instead of \beta emphasis more the meaning. Similarly, \oplus does not give any information on the meaning, it only says "put a plus in an o shape", so to me it’s not better than ⊕. Similarly, many symbols have a well established meaning: nobody uses \plus, instead of +: so why can’t I type to denote an addition modulo 2 (XOR) instead of \oplus? Similarly, the integral, sum, product… symbols are well established. And nothing prevents someone interested to change the symbols to redefine ⊕ to print another symbol. – tobiasBora Apr 12 '23 at 20:04
  • there is no problem with ⊕ or +, the beta depends, perhaps you actually mean , the superscripts are simply wrong as they are never used in unicode math. – Ulrike Fischer Apr 12 '23 at 20:22
  • @UlrikeFischer What do you mean? Quoting the documentation of the unicode-math package "You may, if you wish, use Unicode subscripts and superscripts in your source document. For basic expressions, the use of these characters can make the input more readable. Adjacent sub- or super-scripts will be concatenated into a single expression." https://texlive.mycozy.space/macros/unicodetex/latex/unicode-math/unicode-math.pdf – tobiasBora Apr 13 '23 at 07:11
  • they make the input more readable but nothing more. Unlike ⊕ they are not the symbol used in the output, they only look similar. – Ulrike Fischer Apr 13 '23 at 07:17

0 Answers0