[Latex]ifhen 宏包的使用

来源:互联网 发布:淘宝双11秒杀在哪里找 编辑:程序博客网 时间:2024/05/18 18:04

[Latex]ifhen 宏包的使用提供了两个强大的判断条件:

\ifthenelse{判断条件}{肯定结构}{否定结构}

\whiledo{判断条件}{while语句}

下面是个简单示例:

\documentclass{article}\usepackage{ifthen}\begin{document}\newcommand{\oddeven}[1]{Number #1 is %\ifthenelse{\isodd{#1}}{odd}{even}  }\oddeven{4}.\\ \oddeven{5}\newcounter{MYctr}\whiledo{\value{MYctr}<5}%{ ~\LaTeX~  %\stepcounter{MYctr}}\end{document} 

结果如下:

下面的例子,使用循环判断来实现PDF动画的例子:

\documentclass[10pt]{beamer}\usepackage[utf8]{inputenc} \usepackage{color}\usepackage{tikz}\usepackage{hyperref}\hypersetup{pdfpagemode=FullScreen}\usepackage{ifthen}\usepackage{animate}%\usetheme{Warsaw} \usecolortheme{whale}%\begin{document}%\newcounter{m}\setcounter{m}{0}\newcounter{mc}%\begin{frame}[fragile]{Animated Integral}\begin{center}\begin{animateinline}[loop, poster = first, controls, palindrome]{2}\whiledo{\them < 21}{    \begin{tikzpicture}[scale=1.25]    \draw[red,thick,<->] (-1,1) parabola bend (0,0) (2.1,4.41)        node[below right] {$y=x^2$};    \draw[loosely dotted] (-1,0) grid (4,4);    %\path[use as bounding box] (-2,-1) rectangle (5,5);    \draw[->] (-0.2,0) -- (4.25,0) node[right] {$x$};    \draw[->] (0,-0.25) -- (0,4.25) node[above] {$y$};    \setcounter{mc}{\value{m}*\value{m}}    \shade[top color=blue,bottom color=gray!50]        (0,0) parabola (0.1*\them,0.01*\themc) |- (0,0);    \end{tikzpicture}    %    \stepcounter{m}    \ifthenelse{\them < 21}{            \newframe    }{        \end{animateinline}\relax % BREAK    }} % END \whiledo...\end{center}\end{frame}%\end{document}
图示如下:

其实tikz也提供了一个函数ifthenelse(x,y,z),实现同样的功能.记住这和命令\ifthenelse是有区别的.

原创粉丝点击