3

Can someone help me improve upon this command?

\def\mydots{\leavevmode\xleaders\hbox to 0.40em{\hfil.\hfil}\hfill\kern0pt}

I have been using his to fill space between raggedright and ragged left words. However I have begun to use in environments with small horizontal widths (which require line-wrapping) and it begins to break.

The following was created using:

\begin{itemize}
        \item First Line \mydots \textit{10 km}
        \item Second line \mydots \textit{20 meters}
        \item Another entry \mydots \textit{10 dollars}
        \item Some longer distance$^1$ \mydots \textit{20 goals}
        \item Time for parentheses (+1L) \mydots \textit{20 liters}
        \item Time for zero parenthesees \mydots \textit{20 liters}
        \item Time for a really lengthy sentence \mydots \textit{40 euros}
        \item Now-hyphened sentence \mydots \textit{10 doors}
        \item Now-hyphened but really long sentence \mydots \textit{20 points}
        \item another short \mydots \textit{5 verses}
        \item Last one for now$^1$ \mydots \textit{30 days}\\ \rule{0 pt}{0in}$^1$\textit{Sample footnote causing no known issue}
\end{itemize}

Example of wrapping problems As you can see my standard use case is some text followed by \mydots followed by some italic text (but not always, I am looking to make this work under any situation). My difficulty is that I hope to improve this command without modifying its implementation, its part of my .cls and would require manual change of hundreds of files.

Essentially what I want to happen is that all the text following \mydots needs to be forced into one line, linebreaking the pre-\mydots text wherever needed such that at least some of the previous word falls onto the line with the dots.

Example of manual solution I think this could be accomplished by tricking latex into thinking all the text following \mydots is one word. But I'm not sure how to do this.

  • Not sure of what you want exactly ... may be \dotfill\mbox{...} ? – Fran May 11 '15 at 18:43
4

enter image description here

a bit of glue balancing....

\documentclass{article}

\def\mydots{\futurelet\mytmp\xmydots}

\def\xmydots{\ifx\mytmp\textit
\expandafter\xxmydots
\else
\expandafter\xxxmydots
\fi}

\def\xxmydots#1#2{\xxxmydots\mbox{#1{#2}}}

\def\xxxmydots{\leavevmode
\unskip\nobreak\space
\null\nobreak\xleaders\hbox to 0.40em{\hfil.\hfil}\hfill\kern0pt}
\textwidth7cm
\begin{document}

\begin{itemize}\rightskip0pt plus.7\hsize
        \item First Line \mydots \textit{10 km}
        \item Second line \mydots \textit{20 meters}
        \item Another entry \mydots \textit{10 dollars}
        \item Some longer distance$^1$ \mydots \textit{20 goals}
        \item Time for parentheses (+1L) \mydots \textit{20 liters}
        \item Time for zero parenthesees \mydots \textit{20 liters}
        \item Time for a really lengthy sentence \mydots \textit{40 euros}
        \item Now-hyphened sentence \mydots \textit{10 doors}
        \item Now-hyphened but really long sentence \mydots \textit{20 points}
        \item another short \mydots \textit{5 verses}
        \item Last one for now$^1$ \mydots \textit{30 days}\\ \rule{0 pt}{0in}$^1$\textit{Sample footnote causing no known issue}
\end{itemize}

\end{document}
| improve this answer | |
  • 1
    Note that in "10 km" only the first character is in italic. – Fran May 11 '15 at 18:39
  • @ David, Im trying to make this work without requiring the following text to be \textit{}. But I do not understand \def\xxmydots#1#2{\xxxmydots\mbox{#1{#2}}} Can you explain what is being passed as parameters? – Bob May 12 '15 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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