# [texhax] checking if a piece of text stays on one line or more than one line

Heiko Oberdiek heiko.oberdiek at googlemail.com
Tue Oct 11 11:02:43 CEST 2011

```On Tue, Oct 11, 2011 at 07:40:27PM +1100, Vafa Khalighi wrote:

> This is wonderful. I still do not know why it is not working for right to
> left text but I will investigate that. I have another question:

You have to change the test for the horizontal x-position.
How it can be tested, whether the current text mode is
right to left or left to right?

> Now suppose that we test the argument of \mytextbf and our test shows that
> the text inside \mytextbf stays on more than one line, in this condition,
> would it be possible to automatically insert
>
> 1) \foo at beginning of \mytextbf
> 4)\foot at the end of \mytextbf

Yes, both easy, change the line with \textcolor{red} to your needs:
\textcolor{red}{#1} => \foo#1\foo

> 3)\foo at the beginning of each line
> 2) \foo at the end of each line

No. Then you have to use LuaTeX that allows the modification of
node lists even after typesetting (assuming \foo does not change,
how the lines are broken across lines).

Maybe yes, but expensive. Look at soul, it can split a text
in unbreakable portions (at hyphenation points). Then you have
to add labels for *each* portion. Then you have the positions of
the portions and know, where a line starts and ends.
This may work (within the limitations of package `soul',
see its documentation) with small texts. But for larger uses,
keep in mind that the hash table in TeX is limited.

Yours sincerely
Heiko Oberdiek
```