Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm playing around with the new ocgx package. It uses TikZ nodes to place text. Unfortunately, parindent does not work in the nodes. Is there a way to make it work?

Edit (source code)

\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{calc,shadows,ocgx}
\AtBeginDocument{\edef\normalparindent{\the\parindent}}
\begin{document}
\tikzset{
  checkbox/.style={
    draw,circle,line width=.5pt,%
    minimum size=.7em,top color=white,bottom color=cyan,
    fill opacity=1,
    inner sep=0,
    drop shadow={fill=black,shadow xshift=.5mm,shadow yshift=-.5mm},
  },
  mytext/.style={
    text width=\textwidth,align=justify,
    every node={\setlength\parindent{\normalparindent}},
    inner xsep=0pt,
  },
  mycomment/.style={
    text width=\textwidth-2cm,align=justify,
    fill=yellow!20,
    inner xsep=.5cm,
    inner ysep=.5cm,
    outer xsep=.5cm,
    draw=gray,
  }
}

\lipsum[1]

\bigskip
\noindent%
\begin{tikzpicture}    
  \begin{scope}[ocg={name=mytext,ref=mytext}]
    \node[mytext]{\setlength\parindent{\normalparindent}%
      In elementary algebra, the \textbf{binomial theorem} describes the algebraic expansion of powers of a binomial. According to the theorem, it is possible to expand the power $(x + y)^n$ into a sum involving terms of the form $ax^{b}y^{c}$, where the exponents $b$ and $c$ are nonnegative integers with $b + c = n$, and the coefficient $a$ of each term is a specific positive integer depending on $n$ and $b$. When an exponent is zero, the corresponding power is usually omitted from the term.

      This formula and the triangular arrangement of the binomial coefficients are often attributed to Blaise Pascal, who described them in the 17th century, but they were known to many mathematicians who preceded him. The 4th century B.C. Greek mathematician Euclid mentioned the special case of the binomial theorem for exponent 2 as did the 3rd century B.C. Indian mathematician Pingala to higher orders. A more general binomial theorem and the so-called "Pascal's triangle" were known in the 10th-century A.D. to Indian mathematician Halayudha and Persian mathematician Al-Karaji, in the 11th century to Persian poet and mathematician Omar Khayyam, and in the 13th century to Chinese mathematician Yang Hui, who all derived similar results. Al-Karaji also provided a mathematical proof of both the binomial theorem and Pascal's triangle, using mathematical induction.\par
    };%
  \end{scope}
  \begin{scope}[ocg={name=mycomment,status=invisible,ref=mycomment}]
    \node[mycomment]{binomial theorem:
      \begin{align}
        (a+b)^{2} & = a^{2}+2ab+b^{2}\\
        (a-b)^{2} & = a^{2}-2ab+b^{2}\\
        (a+b)(a-b) & = a^{2}-b^{2}
      \end{align}
    };%
  \end{scope}
\end{tikzpicture}
\par
\begin{center}
\begin{tikzpicture}
  \node[checkbox,switch ocg with mark on={mycomment}{mytext,mycomment}]{};
\end{tikzpicture} show formulas 
\end{center}

\bigskip
\lipsum[2]

\end{document}
  • Layer 1

enter image description here

  • Layer 2

enter image description here

  • Layer 2 (new after Edit)

enter image description here

share|improve this question
    
Hum... The ocgx package is not related to this issue. (pgfmanual) The text width option will put the text of a node in a box of the given width (something akin to a {minipage}...) –  Paul Gaborit Oct 1 '12 at 22:02

3 Answers 3

up vote 4 down vote accepted

I don't appear to have a PDF viewer that can cope with the layers so I don't know if this truly works, but I do know a bit about how to get stuff into a node text, so hopefully the following is a positive contribution.

Somewhere, \parindent is getting reset. So before entering the node we need to save the current value. To do that, we need to use a .code handler. At the moment, in your code you have every node={\setlength\parindent{\normalparindent}}. This doesn't actually do anything because every node is meant to be a style which gets executed at every node and you want to use it to execute some code (note that also as this is within mytext which is called in the node's parameters, using it to set every node has no effect as it is called after every node is processed for this node). So we define a new key which executes some code to save the current \parindent. Now we have to insert it back into the stream at the appropriate point. For this, we use the execute at begin node style. This is executed after the node has started its inner minipage (assuming that it will use one) and that's where you want to restore the indentation. Finally, you want a \indent to indent the first paragraph.

This is all achieved with the following modifications to your code:

Near the top:

 \newlength\saveparindent

in your styles:

  mytext/.style={
    text width=\textwidth,align=justify,
    save parindent,
    execute at begin node={\setlength{\parindent}{\saveparindent}\indent},
    inner xsep=0pt,
  },
  save parindent/.code={
    \setlength{\saveparindent}{\parindent}%
  },

and lastly you don't need the \setlength... in the actual node text.

Indentation in TikZ Nodes

share|improve this answer

Apparently, it has been reset by someone (some code fragment? I do not know). Activating it manually works:

\node[mytext]{
    \parindent=50pt
  In elementary algebra, the ....
share|improve this answer
1  
Does it use a \parbox? If it's so, then it's a common issue. Maybe one can add some "every node" code; the problem is to access the "outside" \parindent. One should save it somewhere, say \AtBeginDocument{\edef\normalparindent{\the\parindent}} and then restate \parindent=\normalparindent in the \node. –  egreg Oct 1 '12 at 20:59
    
@egreg I also tried: every node={\setlength\parindent{\normalparindent}}. But it does not work. Inserting \setlength\parindent{\normalparindent} at begin of the node (would be doable in my planned environment) only works for the following paragraphs but not for the first one. –  Josef Oct 2 '12 at 10:39

Edit: with your edited question, this is even more simple. You can use normal paragraphs and just one OCG (with formulas).

Two compilations are required due to the use of picture remember to overlay the formula above the text. The mark coordinate is used to mark the future position of the formulas.

Here is the code:

\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{calc,shadows,ocgx}
\begin{document}
\tikzset{
  checkbox/.style={
    draw,circle,line width=.5pt,%
    minimum size=.7em,top color=white,bottom color=cyan,
    fill opacity=1,
    inner sep=0,
    drop shadow={fill=black,shadow xshift=.5mm,shadow yshift=-.5mm},
  },
  mytext/.style={
    text width=\textwidth,align=justify,
    inner xsep=0pt,
  },
  mycomment/.style={
    text width=\textwidth-2cm,align=justify,
    fill=yellow!20,
    inner xsep=.5cm,
    inner ysep=.5cm,
    outer xsep=.5cm,
    draw=gray,
  }
}

\lipsum[1-2]

In elementary algebra, the \textbf{binomial theorem} describes the
algebraic expansion of powers of a binomial. According to the theorem,
it is possible to expand the power $(x + y)^n$ into a sum involving
terms of the form $ax^{b}y^{c}$, where the exponents $b$ and $c$ are
nonnegative integers with $b + c = n$, and the coefficient $a$ of each
term is a specific positive integer depending on $n$ and $b$. When an
exponent is zero, the corresponding power is usually omitted from the
term.\tikz[overlay,remember picture]\coordinate (mark);

This formula and the triangular arrangement of the binomial
coefficients are often attributed to Blaise Pascal, who described them
in the 17th century, but they were known to many mathematicians who
preceded him. The 4th century B.C. Greek mathematician Euclid
mentioned the special case of the binomial theorem for exponent 2 as
did the 3rd century B.C. Indian mathematician Pingala to higher
orders. A more general binomial theorem and the so-called "Pascal's
triangle" were known in the 10th-century A.D. to Indian mathematician
Halayudha and Persian mathematician Al-Karaji, in the 11th century to
Persian poet and mathematician Omar Khayyam, and in the 13th century
to Chinese mathematician Yang Hui, who all derived similar
results. Al-Karaji also provided a mathematical proof of both the
binomial theorem and Pascal's triangle, using mathematical
induction.

\begin{center}
  % formulas
  \begin{tikzpicture}[overlay,remember picture]
    \path (mark -| current page) coordinate (origin);
    \begin{scope}[ocg={name=mycomment,status=invisible,ref=mycomment}]
      \node[mycomment] at (origin) {%
        binomial theorem:
        \begin{align}
          (a+b)^{2} & = a^{2}+2ab+b^{2}\\
          (a-b)^{2} & = a^{2}-2ab+b^{2}\\
          (a+b)(a-b) & = a^{2}-b^{2}
        \end{align}
      };
    \end{scope}
  \end{tikzpicture}
  % button
  \begin{tikzpicture}
    \node[checkbox,switch ocg with mark off={mycomment}{}]{};
  \end{tikzpicture} show formulas 
\end{center}

\bigskip
\lipsum[2]

\end{document}

First answer: Here is your MWE with normal paragraphs instead of paragraphs in TikZ nodes!

Two compilations are required due to the use of picture remember to overlay the formula above the text.

enter image description here

enter image description here

\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{calc,shadows,ocgx}
\begin{document}
\tikzset{
  checkbox/.style={
    draw,circle,line width=.5pt,%
    minimum size=.7em,top color=white,bottom color=cyan,
    fill opacity=1,
    inner sep=0,
    drop shadow={fill=black,shadow xshift=.5mm,shadow yshift=-.5mm},
  },
  mytext/.style={
    text width=\textwidth,align=justify,
    inner xsep=0pt,
  },
  mycomment/.style={
    text width=\textwidth-2cm,align=justify,
    fill=yellow!20,
    inner xsep=.5cm,
    inner ysep=.5cm,
    outer xsep=.5cm,
    draw=gray,
  }
}

\lipsum[1-2]

\begin{ocg}{mytext}{mytext}{1}
  In elementary algebra, the \textbf{binomial theorem} describes the
  algebraic expansion of powers of a binomial. According to the theorem,
  it is possible to expand the power $(x + y)^n$ into a sum involving
  terms of the form $ax^{b}y^{c}$, where the exponents $b$ and $c$ are
  nonnegative integers with $b + c = n$, and the coefficient $a$ of each
  term is a specific positive integer depending on $n$ and $b$. When an
  exponent is zero, the corresponding power is usually omitted from the
  term.
\end{ocg}
\begin{tikzpicture}[overlay,remember picture]
  \path (0,0 -| current page) coordinate (origin);
  \begin{scope}[ocg={name=mycomment,status=invisible,ref=mycomment}]
    \node[mycomment] at (origin) {binomial theorem:
      \begin{align}
        (a+b)^{2} & = a^{2}+2ab+b^{2}\\
        (a-b)^{2} & = a^{2}-2ab+b^{2}\\
        (a+b)(a-b) & = a^{2}-b^{2}
      \end{align}
    };%
  \end{scope}
\end{tikzpicture}

\begin{ocg}{mytext}{mytext}{1}
  This formula and the triangular arrangement of the binomial
  coefficients are often attributed to Blaise Pascal, who described them
  in the 17th century, but they were known to many mathematicians who
  preceded him. The 4th century B.C. Greek mathematician Euclid
  mentioned the special case of the binomial theorem for exponent 2 as
  did the 3rd century B.C. Indian mathematician Pingala to higher
  orders. A more general binomial theorem and the so-called "Pascal's
  triangle" were known in the 10th-century A.D. to Indian mathematician
  Halayudha and Persian mathematician Al-Karaji, in the 11th century to
  Persian poet and mathematician Omar Khayyam, and in the 13th century
  to Chinese mathematician Yang Hui, who all derived similar
  results. Al-Karaji also provided a mathematical proof of both the
  binomial theorem and Pascal's triangle, using mathematical
  induction.
\end{ocg}

\begin{center}
\begin{tikzpicture}
  \node[checkbox,switch ocg with mark on={mytext}{mycomment}]{};
\end{tikzpicture} show formulas 
\end{center}

\bigskip
\lipsum[2]

\end{document}
share|improve this answer
    
In the meantime i changed my code to: \begin{tikzpicture} \node[checkbox,switch ocg with mark on={mycomment}{mytext,mycomment}]{}; \end{tikzpicture} show formulas Looks better! ;-) With my code it's opaque. In your example it's not and therefore the formulas are almost unreadable. Any chance to change this? –  Josef Oct 2 '12 at 10:45
    
@Josef Sorry, but I don't understand your comment: in my example, formulas are readable! In your code, if you put mycomment twice in switch ocg with mark on, the visibility state of mycomment ocg is switched twice ! –  Paul Gaborit Oct 2 '12 at 11:53
    
With my changed code first only the mytext layer is visible. If i click the checkbox both layers (mytext and mycomment) are visible. If i apply that change to your code example then the mycomment layer is transparent and therefore the formulas are almost unreadable. –  Josef Oct 2 '12 at 12:07
    
Can you edit your question to add your current code? –  Paul Gaborit Oct 2 '12 at 12:10
    
Okay, i will do in a minute! I now uploaded a pic that demonstrate the problem: imgur.com/4sudx –  Josef Oct 2 '12 at 12:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.