Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

migrated from stackoverflow.com Apr 13 '12 at 17:34

This question came from our site for professional and enthusiast programmers.

    
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

2 Answers 2

up vote 3 down vote accepted

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.

Hopefully your text editor wont break that anywhere bad.

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}}}
share|improve this answer
    
That's a good solution, thanks! –  Dahaniel Apr 13 '12 at 12:04
    
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}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.