# avoid space before \textsuperscript in linebreak

I have a lot of

Ca\textsuperscript{2+}


in my text. In my editor I use automatic linebreaking to keep the text readable. Now it sometimes happens that lhe line breaks like this:

Ca
\textsuperscript{2+}


which produces a space between Ca and 2+.

Is there a way to write this code that it would ignore the linebreak or do I have to find a way to change the behaviour of my editor?

• Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. – Werner May 1 '12 at 17:42

How about using semantic markup. I.e. you write what you mean and use macros to format it. That way if you change how you want the text formatted later you don't need to fix it all over the place.

\newcommand{Ion}[2]{#1\textsuperscript{#2}}


Now you can write

Blah blah \Ion{Ca}{2+} blah blah.


And if you decide you later want all your ions formatted in bold you can just change the macro

\newcommand{Ion}[2]{\textbf{#1\textsuperscript{#2}}}

• As I only need Ca2+ I did it like: \def\ca2{Ca\textsuperscript{2+}} – Dahaniel Apr 13 '12 at 12:15
• @Dahaniel: Note that technically you don't need to define it as \ca2, since the 2 does not form part of the command but actually the parameter list (since 2 is not a letter). – Werner Apr 13 '12 at 15:34

While using semantic markup seems preferable, adding a % (comment sign) after "CA" will conceal the line break and hereby get rid of the space.

\documentclass{article}

\begin{document}

\Huge

Ca
\textsuperscript{2+}

Ca%
\textsuperscript{2+}

\end{document}