1

How to inset wire-O bookbinding. I tried the answer here Background notebook template with spiral by @Gonzalo Medina but it doesn't work properly when I compile with XeLaTeX while usin an RTL language as the main language of a documententer image description here

the complete Code:

\documentclass{article}
\usepackage[contents={}]{background}
\usepackage{tikzpagenodes}
\usetikzlibrary{shadows,calc}
\usepackage{lipsum}

\def\ShadowXshift{0.5ex}
\def\ShadowYshift{-0.5ex}

\makeatletter
\define@key{educnotebook}{spiralnumber}{\def\SpiralNumber{#1}}
\define@key{educnotebook}{nbcolorbg}{\def\NbColorBg{#1}}
\define@key{educnotebook}{minorgridcolor}{\def\MinorGridColor{#1}}
\define@key{educnotebook}{majorgridcolor}{\def\MajorGridColor{#1}}
\define@boolkey{educnotebook}{majorgrid}[false]{
\ifKV@educnotebook@majorgrid 
  \def\DrawMajorGrid{
    \path[clip,rounded corners=10pt]
        ([xshift=-30pt,yshift=20pt]current page text area.north west) rectangle
        ([xshift=30pt,yshift=-20pt]current page text area.south east);
    \draw[\MajorGridColor,opacity=0.3]
          ([xshift=30pt,yshift=-20pt]current page text area.south east) grid[step=10mm]
          ([xshift=-30pt,yshift=20pt]current page text area.north west);
  }
\else
  \def\DrawMajorGrid{\relax}
\fi
}
\define@boolkey{educnotebook}{minorgrid}[false]{
\ifKV@educnotebook@minorgrid 
  \def\DrawMinorGrid{
    \path[clip,rounded corners=10pt]
        ([xshift=-30pt,yshift=20pt]current page text area.north west) rectangle
        ([xshift=30pt,yshift=-20pt]current page text area.south east);
    \draw[\MinorGridColor,opacity=0.3]
          ([xshift=30pt,yshift=-20pt]current page text area.south east) grid[step=1mm]
          ([xshift=-30pt,yshift=20pt]current page text area.north west);
  }
\else
  \def\DrawMinorGrid{\relax}
\fi
}
\define@choicekey+{educnotebook}{spiralposition}[\val\nr]{left,right,top}[left]{%
  \ifcase\nr\relax
    \def\SpiralPosition{
      ([xshift=9pt,yshift=3pt-\Valor*\textheight/(\SpiralNumber-1)]current page text area.north west)
    }
    \def\RotateAngle{0}
  \or
    \def\SpiralPosition{
      ([xshift=-9pt,yshift=-5pt-\Valor*\textheight/(\SpiralNumber-1)]current page text area.north east)
    }
    \def\RotateAngle{180}
    \def\ShadowXshift{-0.5ex}
    \def\ShadowYshift{-0.5ex}
  \or
    \def\SpiralPosition{
      ([yshift=-19pt,xshift=5pt+\Valor*\textwidth/(\SpiralNumber-1)]current page text area.north west)
      }
    \def\RotateAngle{270}
  \fi
}{}

\setkeys{educnotebook}{
  nbcolorbg=white,
  minorgrid=false,
  majorgrid=false,
  minorgridcolor=black!20,
  majorgridcolor=black!60,
  spiralposition=left,
  spiralnumber=15
  }
\def\RotateAngle{0}
\def\ShadowXshift{0.5ex}
\def\ShadowYshift{-0.5ex}

\makeatother

\tikzset{
spiral/.pic={
  \draw[rotate=\RotateAngle,
    draw=black,
    left color=black!70,
    right color=black!60,
    middle color=gray!40
    ] 
    (-1.1,-0.35) rectangle ++(10pt,10pt);
  \draw[
    rotate=\RotateAngle,
    double=gray!80,
    double distance=1pt,
    ]
    (-1,-0.2) arc (40:-250:10pt and 2pt);
  \draw[
    rotate=\RotateAngle,
    double=gray!80,
    double distance=1pt,
    ]
    (-1,-0.05) arc (40:-250:10pt and 2pt);
  }
}

\newcommand\EducNotebook[1][]{%
\begingroup
\AddEverypageHook{%
  \setkeys{educnotebook}{#1}%
  \backgroundsetup{
    scale=1,
    opacity=1,
    color=black,
    angle=0,
    contents={
      \tikz[remember picture,overlay]
      {
      \draw[rounded corners=10pt,fill=\NbColorBg,drop shadow={shadow xshift=\ShadowXshift, shadow yshift=\ShadowYshift}]
        ([xshift=-30pt,yshift=20pt]current page text area.north west) rectangle
        ([xshift=30pt,yshift=-20pt]current page text area.south east);
      \foreach \Valor in {0,1,...,\numexpr\SpiralNumber-1\relax}
        \pic at \SpiralPosition {spiral};
      \DrawMajorGrid
      \DrawMinorGrid
      }  
      }
    }
  \BgMaterial
  }
\endgroup
}

\EducNotebook
\usepackage{xepersian}%-----------for RTL language
\settextfont[Scale=1.3]{Arial}
\setlatintextfont[Scale=1.2]{Arial}
\defpersianfont\Sayeh[Scale=1.3]{Arial} 
\usepackage{ptext}
\begin{document}
\lipsum[1-4]
\end{document}
3
  • 4
    See e.g. tex.stackexchange.com/a/229947/194703. There are several posts that do that.
    – user194703
    Apr 25, 2020 at 21:49
  • 4
    BTW, if you want to know how one can find such related posts: one way is a visual search. The link above is the first hit of a Google image search for site:tex.stackexchange.com tikz notebook.
    – user194703
    Apr 25, 2020 at 21:54
  • The answer mentioned as a duplicate works with PDFLaTeX engine, not with XeLaTeX. Apr 25, 2020 at 23:01

1 Answer 1

2

Tikz works with xelatex.

spiral test

I'm not sure where the extra spaces are coming from in the original post, and I also commented out the setkeys part (not sure what that is doing, either).

And I slightly adjusted the right-hand spiral positions (the xshifts and yshifts look to be font dependent).

And I added the backgrounds Tikz library.

And some Wikipedia. Lipsum is too clunky here.

MWE

\documentclass{article}
\usepackage{tikz}
\usepackage[contents={}]{background}
\usepackage{tikzpagenodes}
\usetikzlibrary{shadows,calc,backgrounds}
%\usepackage{lipsum}

\def\ShadowXshift{0.5ex}
\def\ShadowYshift{-0.5ex}

\makeatletter
\define@key{educnotebook}{spiralnumber}{\def\SpiralNumber{#1}}
\define@key{educnotebook}{nbcolorbg}{\def\NbColorBg{#1}}
\define@key{educnotebook}{minorgridcolor}{\def\MinorGridColor{#1}}
\define@key{educnotebook}{majorgridcolor}{\def\MajorGridColor{#1}}
\define@boolkey{educnotebook}{majorgrid}[false]{
\ifKV@educnotebook@majorgrid 
  \def\DrawMajorGrid{
    \path[clip,rounded corners=10pt]
        ([xshift=-30pt,yshift=20pt]current page text area.north west) rectangle
        ([xshift=30pt,yshift=-20pt]current page text area.south east);
    \draw[\MajorGridColor,opacity=0.3]
          ([xshift=30pt,yshift=-20pt]current page text area.south east) grid[step=10mm]
          ([xshift=-30pt,yshift=20pt]current page text area.north west);
  }
\else
  \def\DrawMajorGrid{\relax}
\fi
}
\define@boolkey{educnotebook}{minorgrid}[false]{
\ifKV@educnotebook@minorgrid 
  \def\DrawMinorGrid{
    \path[clip,rounded corners=10pt]
        ([xshift=-30pt,yshift=20pt]current page text area.north west) rectangle
        ([xshift=30pt,yshift=-20pt]current page text area.south east);
    \draw[\MinorGridColor,opacity=0.3]
          ([xshift=30pt,yshift=-20pt]current page text area.south east) grid[step=1mm]
          ([xshift=-30pt,yshift=20pt]current page text area.north west);
  }
\else
  \def\DrawMinorGrid{\relax}
\fi
}
\define@choicekey+{educnotebook}{spiralposition}[\val\nr]{left,right,top}[left]{%
  \ifcase\nr\relax
    \def\SpiralPosition{
      ([xshift=9pt,yshift=3pt-\Valor*\textheight/(\SpiralNumber-1)]current page text area.north west)
    }
    \def\RotateAngle{0}
  \or
    \def\SpiralPosition{
      ([xshift=65pt,yshift=-5pt-\Valor*\textheight/(\SpiralNumber-1)]current page text area.north east)
    }
    \def\RotateAngle{180}
    \def\ShadowXshift{-0.5ex}
    \def\ShadowYshift{-0.5ex}
  \or
    \def\SpiralPosition{
      ([yshift=-19pt,xshift=5pt+\Valor*\textwidth/(\SpiralNumber-1)]current page text area.north west)
      }
    \def\RotateAngle{270}
  \fi
}{}

\setkeys{educnotebook}{
  nbcolorbg=white,
  minorgrid=false,
  majorgrid=false,
  minorgridcolor=black!20,
  majorgridcolor=black!60,
  spiralposition=right,
  spiralnumber=15
  }
\def\RotateAngle{0}
\def\ShadowXshift{0.5ex}
\def\ShadowYshift{-0.5ex}

\makeatother

\tikzset{
spiral/.pic={
  \draw[rotate=\RotateAngle,
    draw=black,
    left color=black!70,
    right color=black!60,
    middle color=gray!40
    ] 
    (-1.1,-0.35) rectangle ++(10pt,10pt);
  \draw[
    rotate=\RotateAngle,
    double=gray!80,
    double distance=1pt,
    ]
    (-1,-0.2) arc (40:-250:10pt and 2pt);
  \draw[
    rotate=\RotateAngle,
    double=gray!80,
    double distance=1pt,
    ]
    (-1,-0.05) arc (40:-250:10pt and 2pt);
  }
}

\newcommand\EducNotebook[1][]{%
\begingroup
\AddEverypageHook{%
%  \setkeys{educnotebook}{#1}%
%  \backgroundsetup{
%    scale=1,
%    opacity=1,
%    color=black,
%    angle=0,
%    contents={
      \tikz[remember picture,overlay]
      {
      \draw[rounded corners=10pt,fill=red!12,drop shadow={shadow xshift=\ShadowXshift, shadow yshift=\ShadowYshift}]
        ([xshift=-30pt,yshift=20pt]current page text area.north west) rectangle
        ([xshift=30pt,yshift=-20pt]current page text area.south east);
      \foreach \Valor in {0,1,...,\numexpr\SpiralNumber-1\relax}
        \pic at \SpiralPosition {spiral};
      \DrawMajorGrid
      \DrawMinorGrid
      }  
%      }%
%    }
%  \BgMaterial
  }
\endgroup
}

\EducNotebook
\usepackage{xepersian}%-----------for RTL language
\settextfont[Scale=1.3]{Arial}
\setlatintextfont[Scale=1.2]{Arial}
\defpersianfont\Sayeh[Scale=1.3]{Arial} 
\usepackage{ptext}
\begin{document}



منظومهٔ شمسی (به عربی: المنظومة الشمسية) یا سامانهٔ خورشیدی[۶] (به انگلیسی: Solar System) سامانه‌ای دربرگیرندهٔ یک ستاره به نام خورشید و شماری اجرام آسمانی دیگر است که در مدارهایی مستقیم یا غیر مستقیم پیرامون آن می‌گردند. 

\[ a^2 + b^2 = c^2 \]



منظومهٔ شمسی (به عربی: المنظومة الشمسية) یا سامانهٔ خورشیدی[۶] (به انگلیسی: Solar System) سامانه‌ای دربرگیرندهٔ یک ستاره به نام خورشید و شماری اجرام آسمانی دیگر است که در مدارهایی مستقیم یا غیر مستقیم پیرامون آن می‌گردند. 



منظومهٔ شمسی (به عربی: المنظومة الشمسية) یا سامانهٔ خورشیدی[۶] (به انگلیسی: Solar System) سامانه‌ای دربرگیرندهٔ یک ستاره به نام خورشید و شماری اجرام آسمانی دیگر است که در مدارهایی مستقیم یا غیر مستقیم پیرامون آن می‌گردند. 



منظومهٔ شمسی (به عربی: المنظومة الشمسية) یا سامانهٔ خورشیدی[۶] (به انگلیسی: Solar System) سامانه‌ای دربرگیرندهٔ یک ستاره به نام خورشید و شماری اجرام آسمانی دیگر است که در مدارهایی مستقیم یا غیر مستقیم پیرامون آن می‌گردند. 
\newpage

\[ a^2 + b^2 = c^2 \]
\end{document}
4
  • Is it possible to change the scale and opacity in this case? Apr 26, 2020 at 19:24
  • @AbdelhakElfengour The pgfmanual has lots of examples of scale= and opacity=, for \draw and fill commands, for elements of a picture to the whole picture. But how would a page-filling shape scale? Also, try changing the fill colour, from red!3 to red!30 to red!60 to red - a background shape has nothing behind it to be transparent about, if that is what you mean.
    – Cicada
    Apr 27, 2020 at 15:07
  • The tikz/pgfmanual is more than 1300 pages. It is well worthwhile reading.
    – Cicada
    Apr 27, 2020 at 15:11
  • Also, rotate the spirals by 180 degrees, for a better look.
    – Cicada
    Apr 27, 2020 at 15:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .