[texhax] checking if a piece of text stays on one line or more than one line
Vafa Khalighi
vafaklg at gmail.com
Tue Oct 11 10:40:27 CEST 2011
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:
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
2) \foo at the end of each line
3)\foo at the beginning of each line
4)\foot at the end of \mytextbf
As an example, lets say that \mytextbf starts at the middle of line 1 and it
finishes at the middle of lines 3, I would need to have:
1) \foo at beginning of \mytextbf
2) \foot at the end of line 1
3) \foo at the beggining of line 2
4) \foo at the end of line 2
5) \foo at the beginning of line 3
6) \foo at the end of \mytextbf
On Tue, Oct 11, 2011 at 6:23 PM, Heiko Oberdiek <
heiko.oberdiek at googlemail.com> wrote:
> On Tue, Oct 11, 2011 at 03:56:57PM +1100, Vafa Khalighi wrote:
>
> > Can you please send a minimal example showing how this works because all
> my
> > attempts with your package so far failed.
>
> \documentclass{article}
> \usepackage{color}
> \usepackage{zref-savepos}
> \makeatletter
> \newcounter{mytextbf at count}
> \newcommand*{\mytextbf at label}[1]{%
> mytextbf@#1@\the\value{mytextbf at count}%
> }
> \newif\ifmytextbf at oneline
> \newcommand*{\mytextbf}[1]{%
> \leavevmode
> \stepcounter{mytextbf at count}%
> \zsavepos{\mytextbf at label{beg}}%
> \mytextbf at onelinefalse
> \ifnum\zposy{\mytextbf at label{beg}}=\zposy{\mytextbf at label{end}} %
> \ifnum\zposx{\mytextbf at label{end}}<\zposx{\mytextbf at label{beg}} %
> \else
> \mytextbf at onelinetrue
> \fi
> \fi
> \nobreak\hspace{0pt}% allow hyphenation
> \zref at ifrefundefined{\mytextbf at label{beg}}{%
> \textbf{#1}%
> }{%
> \ifmytextbf at oneline
> \textcolor{blue}{\textbf{#1}}%
> \else
> \textcolor{red}{\textbf{#1}}%
> \fi
> }%
> \zsavepos{\mytextbf at label{end}}%
> }
> \begin{document}
>
> foo \mytextbf{include enabled primitives} bar bla bla bla
> \mytextbf{include enabled primitives} bla
> \mytextbf{include enabled primitives} end
>
> \end{document}
>
>
> And an extended version that completes the position by the absolute
> page number and uses \newcount to avoid too much trouble with \include.
>
>
> \documentclass{article}
> \usepackage{color}
> \usepackage{zref-savepos,zref-abspos}
> \makeatletter
> \newcount\mytextbf at count
> \mytextbf at count=\z@
> \newcommand*{\mytextbf at beg}{%
> mytextbf-\the\mytextbf at count
> }
> \newcommand*{\mytextbf at end}{%
> mytextbf+\the\mytextbf at count
> }
> \newif\ifmytextbf at oneline
> \newcommand*{\mytextbf}[1]{%
> \leavevmode
> \global\advance\mytextbf at count\@ne
> \zref at savepos
> \zref at labelbyprops{\mytextbf at beg}{abspage,posx,posy}%
> \zref at refused{\mytextbf at beg}%
> \zref at refused{\mytextbf at end}%
> \mytextbf at onelinefalse
> \ifnum\zref at extract{mytextbf at beg}{abspage}=%
> \zref at extract{mytextbf at end}{abspage} %
> \ifnum\zposy{\mytextbf at beg}=%
> \zposy{\mytextbf at end} %
> \ifnum\zposx{\mytextbf at end}<%
> \zposx{\mytextbf at beg} %
> \else
> \mytextbf at onelinetrue
> \fi
> \fi
> \fi
> \nobreak\hspace\z@
> \zref at ifrefundefined{\mytextbf at beg}{%
> \textbf{#1}%
> }{%
> \ifmytextbf at oneline
> \textcolor{blue}{\textbf{#1}}%
> \else
> \textcolor{red}{\textbf{#1}}%
> \fi
> }%
> \zref at savepos
> \zref at labelbyprops{\mytextbf at end}{abspage,posx,posy}%
> }
> \begin{document}
>
> foo \mytextbf{include enabled primitives} bar bla bla bla
> \mytextbf{include enabled primitives} bla
> \mytextbf{include enabled primitives} end
>
> \end{document}
>
>
> Adding support for right-to-left-writing is left as exercise for you.
>
> Yours sincerely
> Heiko Oberdiek
> _______________________________________________
> TeX FAQ: http://www.tex.ac.uk/faq
> Mailing list archives: http://tug.org/pipermail/texhax/
> More links: http://tug.org/begin.html
>
> Automated subscription management: http://tug.org/mailman/listinfo/texhax
> Human mailing list managers: postmaster at tug.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/texhax/attachments/20111011/ff2863a2/attachment.html>
More information about the texhax
mailing list