<div dir="ltr">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:<br><br><br>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<br>
<br>1) \foo at beginning of \mytextbf<br>2) \foo at the end of each line<br>3)\foo at the beginning of each line<br>4)\foot at the end of \mytextbf<br><br>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:<br>
<br>1)  \foo at beginning of \mytextbf<br>2) \foot at the end of line 1<br>3) \foo at the beggining of line 2<br>4) \foo at the end of line 2<br>5) \foo at the beginning of line 3<br>6) \foo at the end of \mytextbf<br><br>
<div class="gmail_quote">On Tue, Oct 11, 2011 at 6:23 PM, Heiko Oberdiek <span dir="ltr"><<a href="mailto:heiko.oberdiek@googlemail.com">heiko.oberdiek@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Tue, Oct 11, 2011 at 03:56:57PM +1100, Vafa Khalighi wrote:<br>
<br>
> Can you please send a minimal example showing how this works because all my<br>
> attempts with your package so far failed.<br>
<br>
</div>\documentclass{article}<br>
\usepackage{color}<br>
\usepackage{zref-savepos}<br>
\makeatletter<br>
\newcounter{mytextbf@count}<br>
\newcommand*{\mytextbf@label}[1]{%<br>
  mytextbf@#1@\the\value{mytextbf@count}%<br>
}<br>
\newif\ifmytextbf@oneline<br>
\newcommand*{\mytextbf}[1]{%<br>
  \leavevmode<br>
  \stepcounter{mytextbf@count}%<br>
  \zsavepos{\mytextbf@label{beg}}%<br>
  \mytextbf@onelinefalse<br>
  \ifnum\zposy{\mytextbf@label{beg}}=\zposy{\mytextbf@label{end}} %<br>
    \ifnum\zposx{\mytextbf@label{end}}<\zposx{\mytextbf@label{beg}} %<br>
    \else<br>
      \mytextbf@onelinetrue<br>
    \fi<br>
  \fi<br>
  \nobreak\hspace{0pt}% allow hyphenation<br>
  \zref@ifrefundefined{\mytextbf@label{beg}}{%<br>
    \textbf{#1}%<br>
  }{%<br>
    \ifmytextbf@oneline<br>
      \textcolor{blue}{\textbf{#1}}%<br>
    \else<br>
      \textcolor{red}{\textbf{#1}}%<br>
    \fi<br>
  }%<br>
  \zsavepos{\mytextbf@label{end}}%<br>
}<br>
\begin{document}<br>
<br>
foo \mytextbf{include enabled primitives} bar bla bla bla<br>
\mytextbf{include enabled primitives} bla<br>
\mytextbf{include enabled primitives} end<br>
<br>
\end{document}<br>
<br>
<br>
And an extended version that completes the position by the absolute<br>
page number and uses \newcount to avoid too much trouble with \include.<br>
<br>
<br>
\documentclass{article}<br>
\usepackage{color}<br>
\usepackage{zref-savepos,zref-abspos}<br>
\makeatletter<br>
\newcount\mytextbf@count<br>
\mytextbf@count=\z@<br>
\newcommand*{\mytextbf@beg}{%<br>
  mytextbf-\the\mytextbf@count<br>
}<br>
\newcommand*{\mytextbf@end}{%<br>
  mytextbf+\the\mytextbf@count<br>
}<br>
\newif\ifmytextbf@oneline<br>
\newcommand*{\mytextbf}[1]{%<br>
  \leavevmode<br>
  \global\advance\mytextbf@count\@ne<br>
  \zref@savepos<br>
  \zref@labelbyprops{\mytextbf@beg}{abspage,posx,posy}%<br>
  \zref@refused{\mytextbf@beg}%<br>
  \zref@refused{\mytextbf@end}%<br>
  \mytextbf@onelinefalse<br>
  \ifnum\zref@extract{mytextbf@beg}{abspage}=%<br>
        \zref@extract{mytextbf@end}{abspage} %<br>
    \ifnum\zposy{\mytextbf@beg}=%<br>
          \zposy{\mytextbf@end} %<br>
      \ifnum\zposx{\mytextbf@end}<%<br>
            \zposx{\mytextbf@beg} %<br>
      \else<br>
        \mytextbf@onelinetrue<br>
      \fi<br>
    \fi<br>
  \fi<br>
  \nobreak\hspace\z@<br>
  \zref@ifrefundefined{\mytextbf@beg}{%<br>
    \textbf{#1}%<br>
  }{%<br>
    \ifmytextbf@oneline<br>
      \textcolor{blue}{\textbf{#1}}%<br>
    \else<br>
      \textcolor{red}{\textbf{#1}}%<br>
    \fi<br>
  }%<br>
  \zref@savepos<br>
  \zref@labelbyprops{\mytextbf@end}{abspage,posx,posy}%<br>
}<br>
\begin{document}<br>
<br>
foo \mytextbf{include enabled primitives} bar bla bla bla<br>
\mytextbf{include enabled primitives} bla<br>
\mytextbf{include enabled primitives} end<br>
<br>
\end{document}<br>
<br>
<br>
Adding support for right-to-left-writing is left as exercise for you.<br>
<div><div></div><div class="h5"><br>
Yours sincerely<br>
  Heiko Oberdiek<br>
_______________________________________________<br>
TeX FAQ: <a href="http://www.tex.ac.uk/faq" target="_blank">http://www.tex.ac.uk/faq</a><br>
Mailing list archives: <a href="http://tug.org/pipermail/texhax/" target="_blank">http://tug.org/pipermail/texhax/</a><br>
More links: <a href="http://tug.org/begin.html" target="_blank">http://tug.org/begin.html</a><br>
<br>
Automated subscription management: <a href="http://tug.org/mailman/listinfo/texhax" target="_blank">http://tug.org/mailman/listinfo/texhax</a><br>
Human mailing list managers: <a href="mailto:postmaster@tug.org">postmaster@tug.org</a><br>
</div></div></blockquote></div><br></div>