5

I have two letters: A and B. In most situations, I'd like them to appear together with no space, e.g. ("AB"), however, if TeX feels it needs a linebreak or to split these across two pages, this is allowed. This could appear as:

AB

Or:

A

B

What can I place between the two letters (or long string of letters), which will allow them to be split across pages?

  • This should leave no space.
  • This should leave no hyphen.
  • This should use the same splitting rules used if the letters actually had a space.

3 Answers 3

5

If you introduce a small 0pt skip in between the letters TeX will not treat them as a word and will allow them to break as you wish. You can create a macro or use them where you require them. (I used the same example from Schweinebacke for convenience and comparison).

\documentclass{article}

\begin{document}
A\hskip0ptB vs. some text, some text, some text, some text, some text, some text, some
text A\hskip0ptB and some text.

A\hskip0ptB vs. some text, some text, some text, some text, some text, some text, some
text A\hskip0ptB and some text.
\end{document}
3
  • 1
    This would also break/remove kerning (e.g. try VA instead of V\hskip0ptA) and so it would result in something like extra space between the characters. Commented Nov 19, 2011 at 9:53
  • 1
    @Schweinebacke Breaking between the letters AB without a hyphen is pretty much bad typography in any case. I wouldn't worry too much over it. From memory using \discretionary would have the same effect.
    – yannisl
    Commented Nov 19, 2011 at 10:01
  • 1
    You are wrong, \discretionary would not remove kerning. Simply replace \discretionary{A}{B}{AB} at my example by \discretionary{V}{A}{VA} to compare it. Commented Nov 19, 2011 at 10:18
6

I would simply use \discretionary for this and define a macro to increase comfort.

\documentclass{article}
\usepackage{xspace}% see http://ctan.org/pkg/xspace
\usepackage[textwidth=2.78in,textheight=0.9in]{geometry}% for demonstration only
\usepackage{showframe}% for demonstration only

\newcommand*{\AB}{\discretionary{A}{B}{AB}\xspace}

\begin{document}
\AB vs. some text, some text, some text, some text, some text, some text, some
text \AB and some text.

\AB vs. some text, some text, some text, some text, some text, some text, some
text \AB and some text.
\end{document}

I've used package showframe to demonstrate the width and height of the text area at my example (suggestion from Werner). I've used very small width and height to demonstrate line break and page break.

Here are snapshots of the relevant area of page 1 and 2: Snapshot of the relevant areas of page 1 and 2

If you want, you may define a more general command:

\documentclass{article}
\usepackage[textwidth=2.78in,textheight=0.9in]{geometry}% for demonstration only
\usepackage{showframe}% for demonstration only

\newcommand*{\breakchars}[2]{\discretionary{#1}{#2}{#1#2}}

\begin{document}
\breakchars AB vs. some text, some text, some text, some text, some text, some
text, some text \breakchars AB and some text.

\breakchars AB vs. some text, some text, some text, some text, some text, some
text, some text \breakchars AB and some text.

\breakchars VA vs. some text, some text, some text, some text, some text, some
text, some text \breakchars VA and some text.

\end{document}

You don't need argument braces at this case, because without the first and second non-space character (letter or other) will be used to be the first and second argument.

The example with VA was made to show, that kerning still works with this suggestion.

3
  • A\discretionary{}{}{}B is simpler, though.
    – egreg
    Commented Nov 19, 2011 at 10:16
  • @egreg: But it would break kerning. Compare: VA \discretionary{V}{A}{VA} V\discretionary{}{}{}A. The first and the second are kerned, at the third the kerning is missing. Commented Nov 19, 2011 at 10:23
  • Yes, it does. :(
    – egreg
    Commented Nov 19, 2011 at 10:26
1
\documentclass[ngerman,english]{article}
\usepackage{babel}
\useshorthands{"}
\addto\extrasenglish{\languageshorthands{ngerman}}
\begin{document}

\begin{minipage}{1cm}% only for demonstration
foo bar baz A""B
and some other words
A""B and the same
\end{minipage}

\end{document}

enter image description here

3
  • 1
    Works nice but breaks kerning of the two letters too. Try it with V""A to see this. Commented Nov 19, 2011 at 10:36
  • 1
    did I said something different? ;-) it is a solution for AB and not VA ...
    – user2478
    Commented Nov 19, 2011 at 10:43
  • 1
    It is a solution for AB if the used font has no kerning entry for this pair. This seems to be common, but who knows … ;-) Maybe it would be good to know more about the real circumstances of the question to distinguish valid caveats from invalid. BTW: If not only pairs but sequences of characters should be handled, your answer would be very useful - my one not. Commented Nov 19, 2011 at 11:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .