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.

How can I improve the code for this animation so that I can write more words? I wanted a smarter code.

\documentclass{article}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{0pt}%

\begin{document}
\foreach \t in {
    L,
    La,
    LaT,
    LaTe,
    LaTeX
    }{
    \begin{tikzpicture}[scale=1]
        \clip[fill=white] (0,-1) rectangle (6,1);
        \node[right] at (1,0) {\Huge \t};
    \end{tikzpicture}
}
\end{document}

enter image description here

share|improve this question
    
Do I need a special version of tikz to run your MWE? I have 2.10 and am getting the error message "Package tikz Error: Extra options not allowed for clipping path command." –  Stephan Lehmke Jul 14 '12 at 4:21
    
I receive the same error, but compilation goes fine by removing the option fill=white to the \clip. –  Claudio Fiandrino Jul 14 '12 at 7:21
add comment

1 Answer

up vote 13 down vote accepted

My humble attempt with the xstring package:

\documentclass{article}

\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{0pt}

\usepackage{xstring}

\def\mytext{Hello world}
\StrLen{\mytext}[\mylen] 

\begin{document}

\foreach \t in {0,...,\mylen}{%
    \begin{tikzpicture}[scale=1]
        \clip[] (0,-1) rectangle (6,1);
        \node[right] at (1,0) {\Huge \StrLeft{\mytext}{\t}};
    \end{tikzpicture}
}%

\end{document}

We can also enclose the code into a new command \typewriter:

\newcommand{\typewriter}[1]{%
\StrLen{#1}[\mylen]
\foreach \t in {0,...,\mylen}{%
    \begin{tikzpicture}[scale=1]
        \clip[] (0,-1) rectangle (6,1);
        \node[right] at (1,0) {\Huge \StrLeft{#1}{\t}};
    \end{tikzpicture}
}%
}%

And then call it:

\typewriter{Hello world}

There we go. :)

share|improve this answer
    
I forgot to mention that I also ran into the error pointed out by Stephan and Claudio, so I also removed fill=white from my code. :) –  Paulo Cereda Jul 14 '12 at 13:14
    
Perfect!!! Thanks. –  Regis da Silva Jul 14 '12 at 20:17
add comment

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.