1

How to increase the length of spirals as in the image using XeLaTeX engine:

\documentclass[12pt,a4paper, openany, notoc]{report}
\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=20mm]
          ([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=120pt,yshift=-5pt-\Valor*\textheight/(\SpiralNumber-1)]current page text area.north east)%the first number is to shift spirals to page edge
    }
    \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=true,%grid
  majorgrid=false,
  minorgridcolor=black!20,
  majorgridcolor=black!60,
  spiralposition=right,
  spiralnumber=28%spiral number
  }
\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=white!12,drop shadow={shadow xshift=\ShadowXshift, shadow yshift=\ShadowYshift}]
        ([xshift=-80pt,yshift=120pt]current page text area.north west) rectangle%Xshift = left line and Yshift = top line
        ([xshift=84pt,yshift=-120pt]current page text area.south east);%Xshift = right line and Yshift = botton line
      \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]{Times New Roman}
\setlatintextfont[Scale=1.2]{Times New Roman}
\defpersianfont\Sayeh[Scale=1.3]{Times New Roman} 
\usepackage{ptext}
\begin{document}

enter image description here

4
  • 1
    Increasing spiralnumber should do. Currently it is set to spiralnumber=20 and you can try spiralnumber=28. (I cannot compile documents with these fonts.)
    – user194703
    Apr 26, 2020 at 21:57
  • Doesn't work, increase the number within the same space. Please what is the common font to be compiled by everyone? Apr 26, 2020 at 22:07
  • 1
    Yes, you are right, it gets only filled within the \textheight. Most users will be fine with your fonts, I am just using a very old editor that only works with ASCII characters. I am too much used to that editor to switch. So you can try to replace \Valor*\textheight by 0.95*\Valor*\paperheight (or with 0.95 replaced by another value <1).
    – user194703
    Apr 26, 2020 at 22:12
  • It gives an error when I put 0.95 "Dimension too large" when I put 0.70, works but doesn't exceed the current limits. Apr 26, 2020 at 22:42

1 Answer 1

3

This is an attempt to make you happy. Most of it is shamelessly stolen from Gonzalo's nice answer. However, it is still major surgery since I changed everything to pgf keys since I am not really familiar with the \setkeys stuff (nor do I think they are anywhere as powerful as pgf keys, but this might be an unqualified opinion). I tested that this compiles with XeLaTeX and all the xepersian packages but cannot tell whether the output is what it should be. In the beginning there is a table that explains you what these keys are good for. It is foreseeable that users want to add additional options, but pgf keys are great in this regard since they allow us to make things upgradable without pain.

\documentclass[12pt,a4paper]{report}
\usepackage{array}
\usepackage{eso-pic}
\usepackage{tikzpagenodes}
\usetikzlibrary{shadows}
\usepackage{lipsum}
\newif\iftikznotebookmajorgrid
\newif\iftikznotebookminorgrid
\tikzset{notebook background/.cd,
left/.initial=30pt,right/.initial=30pt,top/.initial=20pt,bottom/.initial=20pt,
grid left/.initial=10pt,grid right/.initial=10pt,
grid top/.initial=10pt,grid bottom/.initial=10pt,
show major grid/.is if=tikznotebookmajorgrid,
show major grid/.default=true,
major grid/.style={draw=black!60,xstep=20mm,ystep=20mm},
show minor grid/.is if=tikznotebookminorgrid,
show minor grid/.default=true,
minor grid/.style={help lines,xstep=2mm,ystep=2mm},
angle/.initial=0,
spiral number/.initial=20,
spiral position/.is choice,
spiral position/left/.code={\edef\spiralpositioncase{0}},
spiral position/right/.code={\edef\spiralpositioncase{1}},
spiral position/top/.code={\edef\spiralpositioncase{2}},
spiral position=right,
spiral fill ratio/.is choice,
spiral fill ratio/text/.code={\edef\spiralfillratiocase{0}},
spiral fill ratio/paper/.code={\edef\spiralfillratiocase{1}},
spiral fill ratio/fraction of paperheight/.code={\edef\spiralfillratiocase{2}},
spiral fill fraction/.code={\edef\spiralfillratiocase{2}%
\edef\spiralfillratio{#1}},
spiral fill fraction=1,
spiral fill ratio=text,
}
\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\AddNotebookBG[1][]{\AddToShipoutPictureBG{%
\begin{tikzpicture}[overlay,remember picture]
\tikzset{notebook background/.cd,#1}%
\def\pv##1{\pgfkeysvalueof{/tikz/notebook background/##1}}%
\edef\ShadowXshift{0.5ex}
\edef\ShadowYshift{-0.5ex}
\ifcase\spiralfillratiocase
 \def\fillheight{\textheight}
\or
 \def\fillheight{\paperheight}
\or 
 \def\fillheight{\spiralfillratio*\paperheight}
\fi
\ifcase\spiralpositioncase\relax % left,right,top
  \def\SpiralPosition{
    ([xshift=9pt,yshift={3pt-\Valor*\fillheight/(\pv{spiral number}-1)%
    +0.5*\fillheight}]current page text area.west)
  }
  \edef\RotateAngle{0}
\or
  \def\SpiralPosition{
    ([xshift=-9pt,yshift={-5pt-\Valor*\fillheight/(\pv{spiral number}-1)
    +0.5*\fillheight}]current page text area.east)%the first number is to shift spirals to page edge
  }
  \edef\RotateAngle{180}
  \edef\ShadowXshift{-0.5ex}
  \edef\ShadowYshift{-0.5ex}
\or
  \def\SpiralPosition{
    ([yshift=-19pt,xshift={5pt+\Valor*\fillheight/(\pv{spiral number}-1)
    +0.5*\fillheight}]current page text area.north)
    }
  \edef\RotateAngle{270}
\fi
\draw[rounded corners=10pt,fill=white!12,drop shadow={shadow xshift=\ShadowXshift, shadow yshift=\ShadowYshift}]
  ([xshift=-\pv{left},yshift=\pv{top}]current page text area.north west) rectangle%Xshift = left line and Yshift = top line
  ([xshift=\pv{right},yshift=-\pv{bottom}]current page text area.south east);%Xshift = right line and Yshift = botton line
\begin{scope}
\path[clip,rounded corners=10pt]
        ([xshift=-\pv{left}+\pv{grid left},yshift=\pv{top}-\pv{grid top}]current page text area.north west) rectangle
        ([xshift=\pv{right}-\pv{grid right},yshift=-\pv{bottom}+\pv{grid bottom}]current page text area.south east);
\iftikznotebookmajorgrid
 \draw[/tikz/notebook background/major grid]
       ([xshift=\pv{right}-\pv{grid right},yshift=-\pv{bottom}+\pv{grid bottom}]current page text area.south east) 
        grid
       ([xshift=-\pv{left}+\pv{grid left},yshift=\pv{top}-\pv{grid top}]current page text area.north west);
\fi
\iftikznotebookminorgrid
 \draw[/tikz/notebook background/minor grid]
       ([xshift=\pv{right}-\pv{grid right},yshift=-\pv{bottom}+\pv{grid bottom}]current page text area.south east) 
       grid
       ([xshift=-\pv{left}+\pv{grid left},yshift=\pv{top}-\pv{grid top}]current page text area.north west);
\fi
\end{scope}  
\foreach \Valor in {0,1,...,\numexpr\pv{spiral number}-1\relax}
  {\pic at \SpiralPosition {spiral};}
\end{tikzpicture}}}
%
% I have tested this, and it compiles witout error under
% xelatex. Whether the output makes sense I am not able to judge.
% \usepackage{xepersian}%-----------for RTL language
% \settextfont[Scale=1.3]{Times New Roman}
% \setlatintextfont[Scale=1.2]{Times New Roman}
% \defpersianfont\Sayeh[Scale=1.3]{Times New Roman} 
% \usepackage{ptext}

\AddNotebookBG[show minor grid,
show major grid,
spiral position=right,
right=2.2em,
top=2cm,
bottom=2cm,
spiral fill fraction=0.78]

\begin{document}
\begin{center}
\begin{tabular}{>{\ttfamily}lp{0.6\textwidth}}
left & distance between left border of the text area and left border of the
notebook\\
right & distance between rightborder of the text area and left border of the
notebook\\
top & distance between top border of the text area and top border of the
notebook\\
bottom & distance between bottom border of the text area and bottom border of the
notebook\\
grid left & distance between left border of the text area and left border of the
grid\\
grid right & distance between rightborder of the text area and left border of the
grid\\
grid top & distance between top border of the text area and top border of the
grid\\
grid bottom & distance between bottom border of the text area and bottom border of the
grid\\
show major grid & Boolean, if \texttt{true} the major grid will be shown\\
major grid & style of the major grid, initially equal to
\texttt{draw=black!60,xstep=20mm,ystep=20mm}\\
show minor grid & Boolean, if \texttt{true} the major grid will be shown\\
minor grid & style of the minor grid,  initially equal to 
\texttt{help lines,xstep=2mm,ystep=2mm}\\
spiral number & integer number of spirals\\
spiral position & one of \texttt{left}, \texttt{right} or \texttt{top}\\
spiral fill ratio &  one of \texttt{text}, \texttt{paper} or \texttt{fraction}.
if it is \texttt{fraction} then you can choose a fraction of the paper height.\\
spiral fill fraction & fraction of the paper height\\
\end{tabular}
\end{center}

\lipsum[1-20]
\end{document}

enter image description here

As it often happens with such code monsters which are somewhere in between a small package and a quick answer, it is probably true that this one is hard to maintain on the long run, but I tried to solve your problem. It might well be that this is the wrong approach, and, say, something based on tcolorbox is better but even there one has to deal with the large number of options.

You must log in to answer this question.

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