parindent in TikZ node

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 ....

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}

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

Tags:

Tikz Pgf

Ocg