New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document right-to-left writing with xetex and the bidi package #111

Open
ghost opened this Issue Nov 16, 2016 · 6 comments

Comments

Projects
None yet
1 participant
@ghost
Copy link

ghost commented Nov 16, 2016

If you create an ipe figure with textual elements (short text, paragraph, and inline math) for RTL documents using xetex engine and the bidi package

screen shot 2016-11-17 at 1 34 26 am

then ipe fails to create that textual element for you (the compilation fails).

I will explain in a separate comment what exactly happens and what ipe can do to fix this issue.

@ghost

This comment has been minimized.

Copy link
Author

ghost commented Nov 17, 2016

When you create a text label in an ipe figure, ipe will create the tex file ipetemp.tex with the following contents

\nonstopmode
\documentclass{article}
\usepackage{xcolor}
\newdimen\ipefs
\newcounter{ipePage}\newcounter{ipeView}
\newcounter{ipePages}\newcounter{ipeViews}
\newcommand{\PageTitle}[1]{#1}
\newcommand{\ipesymbol}[4]{$\bullet$}
\definecolor{red}{rgb}{1,0,0}
\definecolor{green}{rgb}{0,1,0}
\definecolor{blue}{rgb}{0,0,1}
\definecolor{yellow}{rgb}{1,1,0}
\definecolor{orange}{rgb}{1,0.647,0}
\definecolor{gold}{rgb}{1,0.843,0}
\definecolor{purple}{rgb}{0.627,0.125,0.941}
\definecolor{gray}{gray}{0.745}
\definecolor{brown}{rgb}{0.647,0.165,0.165}
\definecolor{navy}{rgb}{0,0,0.502}
\definecolor{pink}{rgb}{1,0.753,0.796}
\definecolor{seagreen}{rgb}{0.18,0.545,0.341}
\definecolor{turquoise}{rgb}{0.251,0.878,0.816}
\definecolor{violet}{rgb}{0.933,0.51,0.933}
\definecolor{darkblue}{rgb}{0,0,0.545}
\definecolor{darkcyan}{rgb}{0,0.545,0.545}
\definecolor{darkgray}{gray}{0.663}
\definecolor{darkgreen}{rgb}{0,0.392,0}
\definecolor{darkmagenta}{rgb}{0.545,0,0.545}
\definecolor{darkorange}{rgb}{1,0.549,0}
\definecolor{darkred}{rgb}{0.545,0,0}
\definecolor{lightblue}{rgb}{0.678,0.847,0.902}
\definecolor{lightcyan}{rgb}{0.878,1,1}
\definecolor{lightgray}{gray}{0.827}
\definecolor{lightgreen}{rgb}{0.565,0.933,0.565}
\definecolor{lightyellow}{rgb}{1,1,0.878}
\definecolor{black}{gray}{0}
\definecolor{white}{gray}{1}
\def\ipesetcolor#1#2#3{\special{pdf:bc [#1 #2 #3]}}
\def\iperesetcolor{\special{pdf:ec}}



\usepackage[RTLdocument=on]{bidi}
\pagestyle{empty}
\newcount\bigpoint\dimen0=0.01bp\bigpoint=\dimen0
\begin{document}
\begin{picture}(500,500)
\special{pdf:obj @ipeforms []}
\setbox0=\hbox{\normalsize
\ipesetcolor{0}{0}{0}%
This is a test.%
\iperesetcolor}
\count0=\dp0\divide\count0 by \bigpoint
\special{ pdf:bxobj @ipeform1
width \the\wd0 \space height \the\ht0 \space depth \the\dp0}%
\usebox0%
\special{pdf:exobj}%
\special{pdf:obj @ipeinfo1 << /IpeId 1 /IpeStretch 1 /IpeDepth \the\count0 /IpeXForm @ipeform1 >>}
\special{pdf:close @ipeinfo1}
\special{pdf:put @ipeforms @ipeinfo1}
\put(0,0){\special{pdf:uxobj @ipeform1}}
\end{picture}
\special{pdf:close @ipeforms}
\special{pdf:put @resources << /Ipe @ipeforms >>}
\end{document}

The problem is that in Knuth TeX--XeT algorithm the \special will be reversed so one has to put them in the reverse order in right to left. Thus, ipe should have the following contents

\nonstopmode
\documentclass{article}
\usepackage{xcolor}
\newdimen\ipefs
\newcounter{ipePage}\newcounter{ipeView}
\newcounter{ipePages}\newcounter{ipeViews}
\newcommand{\PageTitle}[1]{#1}
\newcommand{\ipesymbol}[4]{$\bullet$}
\definecolor{red}{rgb}{1,0,0}
\definecolor{green}{rgb}{0,1,0}
\definecolor{blue}{rgb}{0,0,1}
\definecolor{yellow}{rgb}{1,1,0}
\definecolor{orange}{rgb}{1,0.647,0}
\definecolor{gold}{rgb}{1,0.843,0}
\definecolor{purple}{rgb}{0.627,0.125,0.941}
\definecolor{gray}{gray}{0.745}
\definecolor{brown}{rgb}{0.647,0.165,0.165}
\definecolor{navy}{rgb}{0,0,0.502}
\definecolor{pink}{rgb}{1,0.753,0.796}
\definecolor{seagreen}{rgb}{0.18,0.545,0.341}
\definecolor{turquoise}{rgb}{0.251,0.878,0.816}
\definecolor{violet}{rgb}{0.933,0.51,0.933}
\definecolor{darkblue}{rgb}{0,0,0.545}
\definecolor{darkcyan}{rgb}{0,0.545,0.545}
\definecolor{darkgray}{gray}{0.663}
\definecolor{darkgreen}{rgb}{0,0.392,0}
\definecolor{darkmagenta}{rgb}{0.545,0,0.545}
\definecolor{darkorange}{rgb}{1,0.549,0}
\definecolor{darkred}{rgb}{0.545,0,0}
\definecolor{lightblue}{rgb}{0.678,0.847,0.902}
\definecolor{lightcyan}{rgb}{0.878,1,1}
\definecolor{lightgray}{gray}{0.827}
\definecolor{lightgreen}{rgb}{0.565,0.933,0.565}
\definecolor{lightyellow}{rgb}{1,1,0.878}
\definecolor{black}{gray}{0}
\definecolor{white}{gray}{1}
\def\ipesetcolor#1#2#3{\special{pdf:bc [#1 #2 #3]}}
\def\iperesetcolor{\special{pdf:ec}}



\usepackage[RTLdocument=on]{bidi}
\pagestyle{empty}
\newcount\bigpoint\dimen0=0.01bp\bigpoint=\dimen0


\makeatletter

\long\def\bidi@addto#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}}

\bgroup \catcode`!=3 \catcode`?=3
\gdef\bidi@replacestrings#1#2{\long\def\bidi@replacestringsA##1#1##2!{%
   \ifx!##2!\bidi@addto\bidi@tmpb{##1}\else\bidi@addto\bidi@tmpb{##1#2}\bidi@replacestringsA##2!\fi}%
   \edef\bidi@tmpb{\expandafter}\expandafter\bidi@replacestringsA\bidi@tmpb?#1!%
   \long\def\bidi@replacestringsA##1?{\def\bidi@tmpb{##1}}\expandafter\bidi@replacestringsA\bidi@tmpb
}
\egroup



\newbox\bidi@color@start@box  \newbox\bidi@color@end@box
\setbox\bidi@color@start@box=\hbox{\iperesetcolor}
\setbox\bidi@color@end@box=\hbox{\ipesetcolor{0}{0}{0}}%

\def\bidicolor#1{\def\bidi@tmpb{#1}\bidi@replacestrings{ }{\bidi@specialspace}%
   {\copy\bidi@color@start@box\bidi@tmpb\copy\bidi@color@end@box}%
}
\def\bidi@specialspace{%
   \discretionary{\copy\bidi@color@end@box}{\copy\bidi@color@start@box}{\kern\fontdimen2\font}%      
   \nobreak\hskip 0pt plus\fontdimen3\font minus\fontdimen4\font
}

\newcommand*{\iperemoveunit}[1]{\strip@pt#1}

\newcommand*{\ifiperighttoleft}{%
  \if@RTL
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}
\makeatother



\begin{document}
\ifiperighttoleft{%
\special{pdf:put @resources << /Ipe @ipeforms >>}
\special{pdf:close @ipeforms}
\begin{picture}(500,500)
\setbox0=\hbox{\bidicolor{\normalsize
This is just a test.}}
\count0=\dp0\divide\count0 by \bigpoint
\put(\iperemoveunit{\dimexpr500pt-\wd0\relax},0){\special{pdf:uxobj @ipeform1}}%
\special{pdf:put @ipeforms @ipeinfo1}%
\special{pdf:close @ipeinfo1}%
\special{pdf:obj @ipeinfo1 << /IpeId 1 /IpeStretch 1 /IpeDepth \the\count0 /IpeXForm @ipeform1 >>}
\special{pdf:exobj}%
\usebox0%
\special{ pdf:bxobj @ipeform1
width \the\wd0 \space height \the\ht0 \space depth \the\dp0}%
\special{pdf:obj @ipeforms []}
\end{picture}
}{%
\begin{picture}(500,500)
\special{pdf:obj @ipeforms []}
\setbox0=\hbox{\normalsize
\ipesetcolor{0}{0}{0}%
This is just a test.%
\iperesetcolor}
\count0=\dp0\divide\count0 by \bigpoint
\special{ pdf:bxobj @ipeform1
width \the\wd0 \space height \the\ht0 \space depth \the\dp0}%
\usebox0%
\special{pdf:exobj}%
\special{pdf:obj @ipeinfo1 << /IpeId 1 /IpeStretch 1 /IpeDepth \the\count0 /IpeXForm @ipeform1 >>}
\special{pdf:close @ipeinfo1}
\special{pdf:put @ipeforms @ipeinfo1}
\put(0,0){\special{pdf:uxobj @ipeform1}}
\end{picture}
\special{pdf:close @ipeforms}
\special{pdf:put @resources << /Ipe @ipeforms >>}
}
\end{document}
@ghost

This comment has been minimized.

Copy link
Author

ghost commented Nov 17, 2016

When you create a mathematical symbol in an ipe figure, ipe will create the tex file ipetemp.tex with the following contents

\nonstopmode
\documentclass{article}
\usepackage{xcolor}
\newdimen\ipefs
\newcounter{ipePage}\newcounter{ipeView}
\newcounter{ipePages}\newcounter{ipeViews}
\newcommand{\PageTitle}[1]{#1}
\newcommand{\ipesymbol}[4]{$\bullet$}
\definecolor{red}{rgb}{1,0,0}
\definecolor{green}{rgb}{0,1,0}
\definecolor{blue}{rgb}{0,0,1}
\definecolor{yellow}{rgb}{1,1,0}
\definecolor{orange}{rgb}{1,0.647,0}
\definecolor{gold}{rgb}{1,0.843,0}
\definecolor{purple}{rgb}{0.627,0.125,0.941}
\definecolor{gray}{gray}{0.745}
\definecolor{brown}{rgb}{0.647,0.165,0.165}
\definecolor{navy}{rgb}{0,0,0.502}
\definecolor{pink}{rgb}{1,0.753,0.796}
\definecolor{seagreen}{rgb}{0.18,0.545,0.341}
\definecolor{turquoise}{rgb}{0.251,0.878,0.816}
\definecolor{violet}{rgb}{0.933,0.51,0.933}
\definecolor{darkblue}{rgb}{0,0,0.545}
\definecolor{darkcyan}{rgb}{0,0.545,0.545}
\definecolor{darkgray}{gray}{0.663}
\definecolor{darkgreen}{rgb}{0,0.392,0}
\definecolor{darkmagenta}{rgb}{0.545,0,0.545}
\definecolor{darkorange}{rgb}{1,0.549,0}
\definecolor{darkred}{rgb}{0.545,0,0}
\definecolor{lightblue}{rgb}{0.678,0.847,0.902}
\definecolor{lightcyan}{rgb}{0.878,1,1}
\definecolor{lightgray}{gray}{0.827}
\definecolor{lightgreen}{rgb}{0.565,0.933,0.565}
\definecolor{lightyellow}{rgb}{1,1,0.878}
\definecolor{black}{gray}{0}
\definecolor{white}{gray}{1}
\def\ipesetcolor#1#2#3{\special{pdf:bc [#1 #2 #3]}}
\def\iperesetcolor{\special{pdf:ec}}



\usepackage[RTLdocument]{bidi}
\pagestyle{empty}
\newcount\bigpoint\dimen0=0.01bp\bigpoint=\dimen0
\begin{document}
\begin{picture}(500,500)
\special{pdf:obj @ipeforms []}
\setbox0=\hbox{\normalsize
\ipesetcolor{0}{0}{0}%
$1+2+3+\cdots+n=\frac{1}{2}n(n+1)$%
\iperesetcolor}
\count0=\dp0\divide\count0 by \bigpoint
\special{ pdf:bxobj @ipeform1
width \the\wd0 \space height \the\ht0 \space depth \the\dp0}%
\usebox0%
\special{pdf:exobj}%
\special{pdf:obj @ipeinfo1 << /IpeId 1 /IpeStretch 1 /IpeDepth \the\count0 /IpeXForm @ipeform1 >>}
\special{pdf:close @ipeinfo1}
\special{pdf:put @ipeforms @ipeinfo1}
\put(0,0){\special{pdf:uxobj @ipeform1}}
\end{picture}
\special{pdf:close @ipeforms}
\special{pdf:put @resources << /Ipe @ipeforms >>}
\end{document}

ipe should have the following contents

\nonstopmode
\documentclass{article}
\usepackage{xcolor}
\newdimen\ipefs
\newcounter{ipePage}\newcounter{ipeView}
\newcounter{ipePages}\newcounter{ipeViews}
\newcommand{\PageTitle}[1]{#1}
\newcommand{\ipesymbol}[4]{$\bullet$}
\definecolor{red}{rgb}{1,0,0}
\definecolor{green}{rgb}{0,1,0}
\definecolor{blue}{rgb}{0,0,1}
\definecolor{yellow}{rgb}{1,1,0}
\definecolor{orange}{rgb}{1,0.647,0}
\definecolor{gold}{rgb}{1,0.843,0}
\definecolor{purple}{rgb}{0.627,0.125,0.941}
\definecolor{gray}{gray}{0.745}
\definecolor{brown}{rgb}{0.647,0.165,0.165}
\definecolor{navy}{rgb}{0,0,0.502}
\definecolor{pink}{rgb}{1,0.753,0.796}
\definecolor{seagreen}{rgb}{0.18,0.545,0.341}
\definecolor{turquoise}{rgb}{0.251,0.878,0.816}
\definecolor{violet}{rgb}{0.933,0.51,0.933}
\definecolor{darkblue}{rgb}{0,0,0.545}
\definecolor{darkcyan}{rgb}{0,0.545,0.545}
\definecolor{darkgray}{gray}{0.663}
\definecolor{darkgreen}{rgb}{0,0.392,0}
\definecolor{darkmagenta}{rgb}{0.545,0,0.545}
\definecolor{darkorange}{rgb}{1,0.549,0}
\definecolor{darkred}{rgb}{0.545,0,0}
\definecolor{lightblue}{rgb}{0.678,0.847,0.902}
\definecolor{lightcyan}{rgb}{0.878,1,1}
\definecolor{lightgray}{gray}{0.827}
\definecolor{lightgreen}{rgb}{0.565,0.933,0.565}
\definecolor{lightyellow}{rgb}{1,1,0.878}
\definecolor{black}{gray}{0}
\definecolor{white}{gray}{1}
\def\ipesetcolor#1#2#3{\special{pdf:bc [#1 #2 #3]}}
\def\iperesetcolor{\special{pdf:ec}}



\usepackage[RTLdocument=on]{bidi}
\pagestyle{empty}
\newcount\bigpoint\dimen0=0.01bp\bigpoint=\dimen0


\makeatletter

\long\def\bidi@addto#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}}

\bgroup \catcode`!=3 \catcode`?=3
\gdef\bidi@replacestrings#1#2{\long\def\bidi@replacestringsA##1#1##2!{%
   \ifx!##2!\bidi@addto\bidi@tmpb{##1}\else\bidi@addto\bidi@tmpb{##1#2}\bidi@replacestringsA##2!\fi}%
   \edef\bidi@tmpb{\expandafter}\expandafter\bidi@replacestringsA\bidi@tmpb?#1!%
   \long\def\bidi@replacestringsA##1?{\def\bidi@tmpb{##1}}\expandafter\bidi@replacestringsA\bidi@tmpb
}
\egroup



\newbox\bidi@color@start@box  \newbox\bidi@color@end@box
\setbox\bidi@color@start@box=\hbox{\iperesetcolor}
\setbox\bidi@color@end@box=\hbox{\ipesetcolor{0}{0}{0}}%

\def\bidicolor#1{\def\bidi@tmpb{#1}\bidi@replacestrings{ }{\bidi@specialspace}%
   {\copy\bidi@color@start@box\bidi@tmpb\copy\bidi@color@end@box}%
}
\def\bidi@specialspace{%
   \discretionary{\copy\bidi@color@end@box}{\copy\bidi@color@start@box}{\kern\fontdimen2\font}%      
   \nobreak\hskip 0pt plus\fontdimen3\font minus\fontdimen4\font
}

\newcommand*{\iperemoveunit}[1]{\strip@pt#1}

\newcommand*{\ifiperighttoleft}{%
  \if@RTL
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}
\makeatother



\begin{document}
\ifiperighttoleft{%
\special{pdf:put @resources << /Ipe @ipeforms >>}
\special{pdf:close @ipeforms}
\begin{picture}(500,500)
\setbox0=\hbox{\bidicolor{\normalsize
$1+2+3+\cdots+n=\frac{1}{2}n(n+1)$}}
\count0=\dp0\divide\count0 by \bigpoint
\put(\iperemoveunit{\dimexpr500pt-\wd0\relax},0){\special{pdf:uxobj @ipeform1}}%
\special{pdf:put @ipeforms @ipeinfo1}%
\special{pdf:close @ipeinfo1}%
\special{pdf:obj @ipeinfo1 << /IpeId 1 /IpeStretch 1 /IpeDepth \the\count0 /IpeXForm @ipeform1 >>}
\special{pdf:exobj}%
\usebox0%
\special{ pdf:bxobj @ipeform1
width \the\wd0 \space height \the\ht0 \space depth \the\dp0}%
\special{pdf:obj @ipeforms []}
\end{picture}
}{%
\begin{picture}(500,500)
\special{pdf:obj @ipeforms []}
\setbox0=\hbox{\normalsize
\ipesetcolor{0}{0}{0}%
$1+2+3+\cdots+n=\frac{1}{2}n(n+1)$%
\iperesetcolor}
\count0=\dp0\divide\count0 by \bigpoint
\special{ pdf:bxobj @ipeform1
width \the\wd0 \space height \the\ht0 \space depth \the\dp0}%
\usebox0%
\special{pdf:exobj}%
\special{pdf:obj @ipeinfo1 << /IpeId 1 /IpeStretch 1 /IpeDepth \the\count0 /IpeXForm @ipeform1 >>}
\special{pdf:close @ipeinfo1}
\special{pdf:put @ipeforms @ipeinfo1}
\put(0,0){\special{pdf:uxobj @ipeform1}}
\end{picture}
\special{pdf:close @ipeforms}
\special{pdf:put @resources << /Ipe @ipeforms >>}
}
\end{document}
@ghost

This comment has been minimized.

Copy link
Author

ghost commented Nov 17, 2016

When you create a paragraph in an ipe figure, ipe will create the tex file ipetemp.tex with the following contents

\nonstopmode
\documentclass{article}
\usepackage{xcolor}
\newdimen\ipefs
\newcounter{ipePage}\newcounter{ipeView}
\newcounter{ipePages}\newcounter{ipeViews}
\newcommand{\PageTitle}[1]{#1}
\newcommand{\ipesymbol}[4]{$\bullet$}
\definecolor{red}{rgb}{1,0,0}
\definecolor{green}{rgb}{0,1,0}
\definecolor{blue}{rgb}{0,0,1}
\definecolor{yellow}{rgb}{1,1,0}
\definecolor{orange}{rgb}{1,0.647,0}
\definecolor{gold}{rgb}{1,0.843,0}
\definecolor{purple}{rgb}{0.627,0.125,0.941}
\definecolor{gray}{gray}{0.745}
\definecolor{brown}{rgb}{0.647,0.165,0.165}
\definecolor{navy}{rgb}{0,0,0.502}
\definecolor{pink}{rgb}{1,0.753,0.796}
\definecolor{seagreen}{rgb}{0.18,0.545,0.341}
\definecolor{turquoise}{rgb}{0.251,0.878,0.816}
\definecolor{violet}{rgb}{0.933,0.51,0.933}
\definecolor{darkblue}{rgb}{0,0,0.545}
\definecolor{darkcyan}{rgb}{0,0.545,0.545}
\definecolor{darkgray}{gray}{0.663}
\definecolor{darkgreen}{rgb}{0,0.392,0}
\definecolor{darkmagenta}{rgb}{0.545,0,0.545}
\definecolor{darkorange}{rgb}{1,0.549,0}
\definecolor{darkred}{rgb}{0.545,0,0}
\definecolor{lightblue}{rgb}{0.678,0.847,0.902}
\definecolor{lightcyan}{rgb}{0.878,1,1}
\definecolor{lightgray}{gray}{0.827}
\definecolor{lightgreen}{rgb}{0.565,0.933,0.565}
\definecolor{lightyellow}{rgb}{1,1,0.878}
\definecolor{black}{gray}{0}
\definecolor{white}{gray}{1}
\def\ipesetcolor#1#2#3{\special{pdf:bc [#1 #2 #3]}}
\def\iperesetcolor{\special{pdf:ec}}



\usepackage[RTLdocument]{bidi}
\pagestyle{empty}
\newcount\bigpoint\dimen0=0.01bp\bigpoint=\dimen0
\begin{document}
\begin{picture}(500,500)
\special{pdf:obj @ipeforms []}
\setbox0=\hbox{\begin{minipage}{384bp}\normalsize
\ipesetcolor{0}{0}{0}%
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
\end{minipage}\iperesetcolor}
\count0=\dp0\divide\count0 by \bigpoint
\special{ pdf:bxobj @ipeform1
width \the\wd0 \space height \the\ht0 \space depth \the\dp0}%
\usebox0%
\special{pdf:exobj}%
\special{pdf:obj @ipeinfo1 << /IpeId 1 /IpeStretch 1 /IpeDepth \the\count0 /IpeXForm @ipeform1 >>}
\special{pdf:close @ipeinfo1}
\special{pdf:put @ipeforms @ipeinfo1}
\put(0,0){\special{pdf:uxobj @ipeform1}}
\end{picture}
\special{pdf:close @ipeforms}
\special{pdf:put @resources << /Ipe @ipeforms >>}
\end{document}

ipe should have the following contents

\nonstopmode
\documentclass{article}
\usepackage{xcolor}
\newdimen\ipefs
\newcounter{ipePage}\newcounter{ipeView}
\newcounter{ipePages}\newcounter{ipeViews}
\newcommand{\PageTitle}[1]{#1}
\newcommand{\ipesymbol}[4]{$\bullet$}
\definecolor{red}{rgb}{1,0,0}
\definecolor{green}{rgb}{0,1,0}
\definecolor{blue}{rgb}{0,0,1}
\definecolor{yellow}{rgb}{1,1,0}
\definecolor{orange}{rgb}{1,0.647,0}
\definecolor{gold}{rgb}{1,0.843,0}
\definecolor{purple}{rgb}{0.627,0.125,0.941}
\definecolor{gray}{gray}{0.745}
\definecolor{brown}{rgb}{0.647,0.165,0.165}
\definecolor{navy}{rgb}{0,0,0.502}
\definecolor{pink}{rgb}{1,0.753,0.796}
\definecolor{seagreen}{rgb}{0.18,0.545,0.341}
\definecolor{turquoise}{rgb}{0.251,0.878,0.816}
\definecolor{violet}{rgb}{0.933,0.51,0.933}
\definecolor{darkblue}{rgb}{0,0,0.545}
\definecolor{darkcyan}{rgb}{0,0.545,0.545}
\definecolor{darkgray}{gray}{0.663}
\definecolor{darkgreen}{rgb}{0,0.392,0}
\definecolor{darkmagenta}{rgb}{0.545,0,0.545}
\definecolor{darkorange}{rgb}{1,0.549,0}
\definecolor{darkred}{rgb}{0.545,0,0}
\definecolor{lightblue}{rgb}{0.678,0.847,0.902}
\definecolor{lightcyan}{rgb}{0.878,1,1}
\definecolor{lightgray}{gray}{0.827}
\definecolor{lightgreen}{rgb}{0.565,0.933,0.565}
\definecolor{lightyellow}{rgb}{1,1,0.878}
\definecolor{black}{gray}{0}
\definecolor{white}{gray}{1}
\def\ipesetcolor#1#2#3{\special{pdf:bc [#1 #2 #3]}}
\def\iperesetcolor{\special{pdf:ec}}



\usepackage[RTLdocument=on]{bidi}
\pagestyle{empty}
\newcount\bigpoint\dimen0=0.01bp\bigpoint=\dimen0


\makeatletter

\long\def\bidi@addto#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}}

\bgroup \catcode`!=3 \catcode`?=3
\gdef\bidi@replacestrings#1#2{\long\def\bidi@replacestringsA##1#1##2!{%
   \ifx!##2!\bidi@addto\bidi@tmpb{##1}\else\bidi@addto\bidi@tmpb{##1#2}\bidi@replacestringsA##2!\fi}%
   \edef\bidi@tmpb{\expandafter}\expandafter\bidi@replacestringsA\bidi@tmpb?#1!%
   \long\def\bidi@replacestringsA##1?{\def\bidi@tmpb{##1}}\expandafter\bidi@replacestringsA\bidi@tmpb
}
\egroup



\newbox\bidi@color@start@box  \newbox\bidi@color@end@box
\setbox\bidi@color@start@box=\hbox{\iperesetcolor}
\setbox\bidi@color@end@box=\hbox{\ipesetcolor{0}{0}{0}}%

\def\bidicolor#1{\def\bidi@tmpb{#1}\bidi@replacestrings{ }{\bidi@specialspace}%
   {\copy\bidi@color@start@box\bidi@tmpb\copy\bidi@color@end@box}%
}
\def\bidi@specialspace{%
   \discretionary{\copy\bidi@color@end@box}{\copy\bidi@color@start@box}{\kern\fontdimen2\font}%      
   \nobreak\hskip 0pt plus\fontdimen3\font minus\fontdimen4\font
}

\newcommand*{\iperemoveunit}[1]{\strip@pt#1}

\newcommand*{\ifiperighttoleft}{%
  \if@RTL
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}
\makeatother



\begin{document}
\ifiperighttoleft{%
\special{pdf:put @resources << /Ipe @ipeforms >>}
\special{pdf:close @ipeforms}
\begin{picture}(500,500)
\setbox0=\hbox{\begin{minipage}{384bp}\bidicolor{\normalsize
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.}
\end{minipage}}
\count0=\dp0\divide\count0 by \bigpoint
\put(\iperemoveunit{\dimexpr500pt-\wd0\relax},0){\special{pdf:uxobj @ipeform1}}%
\special{pdf:put @ipeforms @ipeinfo1}%
\special{pdf:close @ipeinfo1}%
\special{pdf:obj @ipeinfo1 << /IpeId 1 /IpeStretch 1 /IpeDepth \the\count0 /IpeXForm @ipeform1 >>}
\special{pdf:exobj}%
\usebox0%
\special{ pdf:bxobj @ipeform1
width \the\wd0 \space height \the\ht0 \space depth \the\dp0}%
\special{pdf:obj @ipeforms []}
\end{picture}
}{%
\begin{picture}(500,500)
\special{pdf:obj @ipeforms []}
\setbox0=\hbox{\begin{minipage}{384bp}\normalsize
\ipesetcolor{0}{0}{0}%
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
\end{minipage}\iperesetcolor}
\count0=\dp0\divide\count0 by \bigpoint
\special{ pdf:bxobj @ipeform1
width \the\wd0 \space height \the\ht0 \space depth \the\dp0}%
\usebox0%
\special{pdf:exobj}%
\special{pdf:obj @ipeinfo1 << /IpeId 1 /IpeStretch 1 /IpeDepth \the\count0 /IpeXForm @ipeform1 >>}
\special{pdf:close @ipeinfo1}
\special{pdf:put @ipeforms @ipeinfo1}
\put(0,0){\special{pdf:uxobj @ipeform1}}
\end{picture}
\special{pdf:close @ipeforms}
\special{pdf:put @resources << /Ipe @ipeforms >>}
}
\end{document}
@ghost

This comment has been minimized.

Copy link
Author

ghost commented Nov 17, 2016

As you can see the three cases are quite similar and there is no need to program each individual case in ipe.

In each modified tex file, I have created two picture environments; one for left to right mode and the other one for right to left mode. I just used two picture environments for you to see things clearly but ideally ipe should only use one picture environment and put things in the right place depending on the direction of writing.

If you have any questions, please let me know.

@ghost ghost changed the title RTL textual objects in ipe does not work RTL textual elements in ipe does not work Nov 17, 2016

@otfried otfried self-assigned this Sep 17, 2018

@otfried

This comment has been minimized.

Copy link
Owner

otfried commented Jan 6, 2019

This seems quite messy. There seems to be a much simpler solution:

Add this to your preamble to load bidi typesetting:

\usepackage{bidi}

Set the TeX engine to xetex.

Now you can write a text object containing LTR text:

\RTL Here is my text. \endRTL

If you run Latex now, it should work correctly.

Of course you don't want to write \RTL and \endRTL every time you make a text object, so you need to define a new text style (or redefine the standard ones) to include this. For instance with a style sheet like this:

<ipestyle name="bidi">
<preamble>
\ipedefinecolors{}
\usepackage{bidi}
</preamble>
<textstyle name="rtl" type="minipage" begin="\RTL{}" end="\endRTL"/>
<textstyle name="rtl" type="label" begin="\hboxR{" end="}"/>
</ipestyle>
@otfried

This comment has been minimized.

Copy link
Owner

otfried commented Jan 6, 2019

Here is an example document using the style sheet above.

bidi2.pdf

Note that this will need Ipe 7.2.8, to be released in a few days (it may work with 7.2.7 if you simply remove the \ipedefinecolors{} command from the style sheet, but I haven't tested that).

Please let me know if there is anything I can do to make RTL writing more usable in Ipe.

@otfried otfried changed the title RTL textual elements in ipe does not work Document right-to-left writing with xetex and the bidi package Jan 11, 2019

@otfried otfried added this to the 7.2.9 milestone Jan 11, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment