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.

For a list of bullet-separated items, I want the separator to be swallowed if it is the first or last element of the line. That is, I want something like

\renewcommand{\and}{%
  \ifnolinebreak%    <=== HERE'S THE PROBLEM
    {\hfill\textbullet\hfill\xspace}%
  \else{}\fi
}
Aa Bb \and Cc Dd \and veryveryverylongE \and Ff Gg \and H

to end up like

Aa Bb   *   Cc Dd
veryveryverylongE
Ff Gg     *     H

I know that \discretionary can be exploited in the following way:

\renewcommand{\and}{\discretionary{}{}{\mbox{~~{\textbullet}~~}}}

This does the job, but unfortunately I can't find a way to insert a stretchable skip in the discretionary definition. Thus, it looks awkward in justified mode:

Aa   Bb * Cc   Dd
veryveryverylongE
Ff         Gg * H

Any ideas how to implement the \ifnolinebreak? If it matters, for this project I use LuaLaTeX...

share|improve this question

1 Answer 1

up vote 16 down vote accepted

Borrowing code by Marcin Woliński published as the TeX pearl "How to make a box disappear at a line break" one can do

\documentclass{article}
\newcommand{\AND}{\unskip
  \hskip 2pt plus 1pt minus 1pt
  \cleaders\copy\ANDbox\hskip\wd\ANDbox
  \hskip 2pt plus 1pt minus 1pt
  \ignorespaces}
\newsavebox\ANDbox
\sbox\ANDbox{\textbullet}

\begin{document}
\settowidth{\dimen0}{someveryverylongword}
\parbox{\dimen0}{
some text \AND some text \AND
someveryverylongword \AND
text \AND text}
\end{document}

enter image description here

share|improve this answer
    
Thanks a lot, this works great! –  perpeduumimmobile Feb 18 '12 at 16:09
    
I am wowed by the cleverness of how you demonstrated that the code actually works. I will have to keep this in mind as it is a lot easier than what I have used in the past: \usepackage[paperwidth=4.0cm]{geometry} and then tweak the value until it is correct. –  Peter Grill Feb 18 '12 at 16:52

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.