2

I read this article about how to make a torn paper effect. So I tried the code below, but some errors arise.

\documentclass[a4paper,11pt,twoside]{book}
\usepackage{lipsum}   % To generate test text
\usepackage{framed}
\usepackage{ifthen}
\usepackage{tikz}
\usepackage[margin=1cm]{geometry}% for screen preview
\usetikzlibrary{decorations.pathmorphing,calc,shadows.blur,shadings}

\newcounter{mathseed}
\setcounter{mathseed}{3}
\pgfmathsetseed{\arabic{mathseed}} % To have predictable results
% Define a background layer, in which the parchment shape is drawn
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

% This is the base for the fractal decoration. It takes a random point between the start and end, and
% raises it a random amount, thus transforming a segment into two, connected at that raised point
% This decoration can be applied again to each one of the resulting segments and so on, in a similar
% way of a Koch snowflake.
\pgfdeclaredecoration{irregular fractal line}{init}
{
  \state{init}[width=\pgfdecoratedinputsegmentremainingdistance]
  {
    \pgfpathlineto{\pgfpoint{random*\pgfdecoratedinputsegmentremainingdistance}{(random*\pgfdecorationsegmentamplitude-0.02)*\pgfdecoratedinputsegmentremainingdistance}}
    \pgfpathlineto{\pgfpoint{\pgfdecoratedinputsegmentremainingdistance}{0pt}}
  }
}

% define some styles
\tikzset{
    paper/.style={draw=black!10, blur shadow, every shadow/.style={opacity=1, black}, shade=bilinear interpolation,
        lower left=black!10, upper left=black!5, upper right=white, lower right=black!5, fill=none},
    irregular cloudy border/.style={decoration={irregular fractal line, amplitude=0.2},
        decorate,
    },
    irregular spiky border/.style={decoration={irregular fractal line, amplitude=-0.2},
        decorate,
    },
    ragged border/.style={ decoration={random steps, segment length=7mm, amplitude=2mm},
        decorate,
    }
}
\tikz{
    \node[inner sep=1em] (A) {#1};  % Draw the text of the node
    \begin{pgfonlayer}{background}  % Draw the shape behind
        \fill[paper] % recursively decorate the bottom border
        \pgfextra{\pgfmathsetseed{\arabic{mathseed}}\addtocounter{mathseed}{1}}%
        {decorate[irregular cloudy border]{decorate{decorate{decorate{decorate[ragged border]{
                                (A.north west) -- (A.north east)
        }}}}}}
        -- (A.south east)
        \pgfextra{\pgfmathsetseed{\arabic{mathseed}}}%
        {decorate[irregular spiky border]{decorate{decorate{decorate{decorate[ragged border]{
                                -- (A.south west)
        }}}}}}
        -- (A.north west);
\end{pgfonlayer}}
}{%
\tikz{
    \node[inner sep=1em] (A) {#1};  % Draw the text of the node
    \begin{pgfonlayer}{background}  % Draw the shape behind
        \fill[paper] % recursively decorate the bottom border
        \pgfextra{\pgfmathsetseed{\arabic{mathseed}}\addtocounter{mathseed}{1}}%
        {decorate[irregular spiky border]{decorate{decorate{decorate{decorate[ragged border]{
                                (A.north east) -- (A.north west)
        }}}}}}
        -- (A.south west)
        \pgfextra{\pgfmathsetseed{\arabic{mathseed}}}%
        {decorate[irregular cloudy border]{decorate{decorate{decorate{decorate[ragged border]{
                                -- (A.south east)
        }}}}}}
        -- (A.north east);
\end{pgfonlayer}}
}}

\begin{document}
\noindent
\tornpaper{
\parbox{.9\textwidth}{\lipsum[11]}
}

\noindent
\tornpaper{
\parbox{.9\textwidth}{\lipsum[15]}
}

\noindent
\tornpaper{
\parbox{.9\textwidth}{\lipsum[5]}
}
\end{document}

The reports are:

  • You can't use 'macro parameter character #' in restricted horizontal mode. \node[inner sep=1em] (A) {#
  • Package pgfkeys Error: Choice 'bilinear interpolation' unknown in choice key '/tikz/shade'. I am going to ignore this key. \fill[paper]
  • Missing \begin{document}. \end{pgfonlayer}}
  • Too many }'s. }
  • You can't use 'macro parameter character #' in restricted horizontal mode. \node[inner sep=1em] (A) {#
  • Package pgfkeys Error: Choice 'bilinear interpolation' unknown in choice key '/tikz/shade'. I am going to ignore this key. \fill[paper]
  • Too many }'s. }}
  • Undefined control sequence. \tornpaper
  • Undefined control sequence. \tornpaper
  • Undefined control sequence. \tornpaper

What is the problem?

Thank's in advance!

closed as off-topic by Paul Stanley, Stefan Pinnow, Circumscribe, Sebastiano, user36296 Jan 17 at 9:55

  • This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    Go back and check the answer you referenced: it was setting up a macro called \tornpaper which had one argument. You've deleted the macro definition, keeping its contents: all your various errors follow predictably from that. – Paul Stanley Jan 16 at 23:14
  • 2
    I confirm what @PaulStanley is saying: if you use the correct, i.e. complete code, and replace, as pointed out in this comment shade=bilinear interpolation by shading=bilinear interpolation, the code works find. (According to what I find the result is great also without any bilinear interpolation.) – marmot Jan 17 at 4:03
  • Thank you both!!! I didn't notice the missing \def\tornpaper#1{% \ifthenelse{\isodd{\value{mathseed}}}{ from the code or the problem with shade=bilinear interpolation. Thank you!!! – Kώστας Κούδας Jan 17 at 6:04
  • 4
    I'm voting to close this question as off-topic because the problem related to a typographic error and the substance was already dealt with fully in an answer linked in the question. – Paul Stanley Jan 17 at 7:51
  • OK. Should I delete this question? – Kώστας Κούδας Jan 17 at 7:54

Browse other questions tagged or ask your own question.