7

I have a lot of places in my dissertation where the plus sign appears surrounded by capital letters in text, e.g. NNLL+NNLO.
The problem is that by default, the + is aligned so low vertically, that among caps it looks badly aligned.
By playing around with the \raisebox, I found that it looks quite a bit better if raised by 0.25ex, and still looks fine with lowercase letters, even in situations like a+j.
Is there a way to change the default behavior of the plus sign to always appear raised in text?
I don't want to change what happens in the math mode.

I suppose a potential solution might be to globally substitute raw + by \raisebox{0.25ex}{+} (modulo the issue with space swallowing) or to make latex use a different font for rendering the +.
I just don't know if that's even possible.


Reporting on what I implemented based on the answers.
Here's the command I came up with that also accounts for bold and allows typesetting of two consecutive raised spaces with \++.

\makeatletter % https://tex.stackexchange.com/a/31660/35990
\newcommand*{\IfbfTF}{% detect bold font
  \ifx\f@series\my@test@bf
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
}
\newcommand*{\my@test@bf}{bx}
\makeatother

% https://tex.stackexchange.com/a/567256/35990 \newcommand{\textplus}[1][+]{\raisebox{% font-independent height \dimexpr(\fontcharht\font`X-\height+\depth)/2\relax }{\IfbfTF{$\bm{#1}$}{#1}}}

\ExplSyntaxOn \NewDocumentCommand+{}{ \peek_charcode_remove:NTF + {\textplus[++]}{\textplus[+]} } \ExplSyntaxOff

\peek_charcode_remove:NTF requires the expl3 package.

SU3
  • 519
  • I am not sure what you mean by "issue with space swallowing" ? + and \raisebox{0.25ex}{+} (and my suggested \+) all have the same behaviour with respect to surrounding white space. – David Carlisle Oct 17 '20 at 22:31
  • If you define \newcommand\myplus{+} and then write \myplus a, it is rendered as '+a' without a space. I assumed the same would also happen for \newcommand\+{+}, which seems to not be the case. Can anyone explain why? – SU3 Oct 17 '20 at 23:37
  • isn't a letter, so \+ terminates at the + just as \$ or \% but you hadn't mentioned a definition, so I thought you meant using \raisebox{..}{+} explicitly, which wouldn't drop spaces either.
  • – David Carlisle Oct 17 '20 at 23:39
  • I also assumed that however a global substitution of + would work, it would internally rely on a new command definition and thus have the usual space problem. I clearly don't understand when space are swallowed and when not. – SU3 Oct 17 '20 at 23:42
  • not sure what you mean by a global substitution, you mean replacing + by \resizebox{}{} in your editor? Yes that would work as well. – David Carlisle Oct 17 '20 at 23:45
  • Like I wrote in the question, I don't know if that is possible in latex, but one could imagine some mechanism that would allow any occurrence of a + in the text mode to be rendered as if \raisebox{..}{+} was written instead. For example, in C you can define macros that perform literal string substitutions in the source code before compilation. The analogy is not complete, because C macros are not context-aware. – SU3 Oct 17 '20 at 23:49
  • as I said in my answer you could do that (same as ~ turns into \nobreakspace) but there are constructs that would break where + is used in arithmetic expressions. If you are feeling brave, define \~ as in my or egreg's answer then do \catcode\+=\active \def+{\relax\ifmmode\string+\else+\fi}` (TeX consists almost entirely of macro expansion in the sense of C macros, and nothing in the sense of C compiled functions) – David Carlisle Oct 17 '20 at 23:51
  • I agree now that \+ seems a better option than redefining the + entirely. But thanks for the explanation. I may find a use for this later. – SU3 Oct 17 '20 at 23:59