KTUGFaq

KTUG FAQ

·Î±×ÀÎ:
ºñ¹Ð¹øÈ£:
°¡ÀÔ
You are going to have a new love affair.
FrontPage › Conditionals

¸ñÂ÷

1 TeXÀÇ Á¶°Ç¹®
1.1 \if
1.2 \ifcat
1.3 \ifx
1.4 Mode °Ë»ç(\ifhmode,\ifvmode,\ifmmode)
1.5 Number °Ë»ç(\ifnum, \ifodd)
1.6 Dimension °Ë»ç(\ifdim)
1.7 Box °Ë»ç(\ifvoid, \ifhbox, \ifvbox)
1.8 ÆÄÀÏ °Ë»ç(\ifeof)
1.9 \iff :)
1.10 Case¹®(\ifcase)
1.11 \newif, \iftrue, \iffalse
2 LaTeX2eÀÇ Á¶°Ç¹®
2.1 LaTeXÀÇ \newif, \iffalse, \iftrue »ç¿ë
2.2 \@if
2.3 \@ifnextchar
2.4 \IfFileExists
2.5 \@ifstar
2.6 \@ifpackageclassloaded, \@ifpackageclasslater, \@ifpackageclasswith
2.7 ifthen ÆÐÅ°Áö
2.7.1 \ifthenelse ¸í·É
2.7.2 \ifthenelse¿¡¼­ ¾²ÀÌ´Â Á¶°Ç °Ë»ç
2.7.3 \newboolean, \setboolean
3 etoolboxÀÇ Á¶°Ç¹®
3.1 boolean
3.2 Á¶°Ç °Ë»ç
4 Loop
4.1 PlainTeXÀÇ \loop \repeat
4.2 ifthen ÆÐÅ°ÁöÀÇ \whiledo
4.3 \for-loop
4.4 multido
5 ÀÀ¿ë : Á¶°ÇºÎ ÄÄÆÄÀÏ
5.1 TTY¸¦ ÅëÇÏ¿© »ç¿ëÀÚ ÀÔ·ÂÀ» ¹Þ¾ÆµéÀÌ´Â ¹æ¹ý
5.2 ¸í·ÉÇàÀ» ÀÌ¿ëÇÏ´Â ¹æ¹ý

1 TeXÀÇ Á¶°Ç¹®


TeXÀÇ if Á¶°Ç¹®Àº ÁÖ·Î ¹®ÀÚ¿Í ControlSequences¸¦ °Ë»çÇϱâ À§ÇÏ¿© »ç¿ëµÈ´Ù. ±¸¹®¹ýÀº ´ÙÀ½°ú °°´Ù.
\if... \fi
\if... \else... \fi

1.1 \if

TeXÀº \if ´ÙÀ½¿¡ ³ª¿À´Â ¸ÅÅ©·ÎµéÀ» Àü°³Çϴµ¥, ¾ðÁ¦±îÁö Çϳĸé Àü°³ÇÒ ¼ö ¾ø´Â ÅäÅ«À» Á¤È®È÷ µÎ °³ ¾òÀ» ¶§±îÁö ÇÑ´Ù. ±×¸®°í³ª¼­ ±× ¾ò¾îÁø µÎ °³ÀÇ ÅäÅ«À» ºñ±³ÇÑ´Ù. µû¶ó¼­ \if¸¦ ÀÌ¿ëÇؼ­ ºñ±³ÇÒ ´ë»óÀÌ Àü°³ °¡´ÉÇÑ ¸ÅÅ©·Î³ª ¾×Ƽºê ¹®ÀÚÀÌ¸é ±×°Íµé ¾Õ¿¡ \noexpand¸¦ ºÙ¿©¼­ Àü°³¸¦ ¸·°í ºñ±³¸¦ ÇؾßÇÑ´Ù. ¿¹¸¦µé¾îº¸ÀÚ.
\def\A{abc} \def\B{abc}
\if\A\B
À§ÀÇ Á¶°Ç¹®ÀÇ °á°ú´Â °ÅÁþÀÌ´Ù. ¿Ö³ÄÇϸé, À§ÀÇ ¼³¸í´ë·Î \if ´ÙÀ½¿¡ ³ª¿À´Â ¸ÅÅ©·Î¸¦ Àü°³Çϴµ¥, ¿©±â¼­´Â \A¸¦ Àü°³ÇϰԵȴÙ. ±×·±µ¥ \A¸¦ Àü°³ÇÏ°í³ª¸é \if abc°¡ µÇ°í, ¹®ÀÚ ÅäÅ« a, b ÀÌ¹Ì µÎ°³ÀÇ Àü°³ÇÒ ¼ö ¾ø´Â ÅäÅ«À» ¾ò¾úÀ¸¹Ç·Î ´õÀÌ»óÀÇ Àü°³¸¦ ¸¶Ä¡°í ±× µÎ°³ÀÇ ÅäÅ«À» ºñ±³ÇÑ´Ù. µû¶ó¼­ \if abÀÇ °á°ú°¡ ÀÌ Á¶°Ç¹®ÀÇ °ªÀÌ µÇ´Âµ¥, ´ç¿¬È÷ a ¿Í b´Â ´Ù¸£¹Ç·Î °ÅÁþÀÌ´Ù.
\def\A{aaa} \def\B{bbb}
\if\A\B
À§ °æ¿ì´Â ¾î¶³±î? ¾Õ¿¡¼­ ÇÑ°Í Ã³·³ Çϸé \if\A\B ´Â °á°úÀûÀ¸·Î \if aa À̹ǷΠÀÌ Á¶°Ç¹®ÀÇ °ªÀº ÂüÀÌ´Ù. ´Ù¸¥ ¿¹¸¦ Çϳª ´õ µé¾îº¸ÀÚ.
\def\pion#1{$\if#1+\pi^+\else\pi^-\fi$}
\if expands the tokens, therefore,
\let\a+
\pion\a
would give the same result as \pion+.

\def\pion#1{$\if#1+\pi^+\else\pi^-\fi$}
\let\a+
\begin{tabular}{lll}
\verb|\pion\a| & °á°ú : & \pion\a \\
\verb|\pion+| &°á°ú : & \pion+
\end{tabular}

1.2 \ifcat

The \if test ignores CategoryCodes; these can be tested by
 \ifcat<token1><token2>
This test is a lot like \if : TEX expands after it until unexpandable tokens remain. For this test ControlSequences are considered to have CategoryCode 16 (ordinarily, category codes are in the range 0–15), which makes them all equal to each other, and different from all character tokens.

1.3 \ifx

°¡Àå ¸¹ÀÌ ¾²´Â \if °ü·Ã ¹®¹ý ÁßÀÇ Çϳª. \ifx<token1><token2>´Â µÎ °³ÀÇ tokenÀÌ ÀÏÄ¡ÇÏ´ÂÁö °Ë»çÇÑ´Ù. ±×·¯³ª ¸í·ÉÀ» È®ÀåÇÏÁö´Â ¾Ê´Â´Ù. ÀÌ Á¶°ÇÀÌ Âü(true)ÀÌ µÇ·Á¸é ´ÙÀ½ Áß ¾î´À Çϳª¿©¾ß ÇÑ´Ù.
  1. µÎ °³ÀÇ tokenÀÌ ¸í·ÉÀÌ ¾Æ´Ò °Í. µ¿ÀÏÇÑ ¹®ÀÚÄÚµå¿Í CategoryCode¸¦ °¡Áö°Å³ª µ¿ÀÏÇÑ TeX ¿ø½Ã¸í·ÉÀ̰ųª µ¿ÀÏÇÑ \font, \chardef, \countdef¿¡ ÀÇÇØ Á¤ÀÇµÈ °ÍÀÏ °Í.
  2. µÎ °³ÀÇ tokenÀÌ ¸í·ÉÀÌ°í \longÀ̳ª \outer¿Í °°Àº »óÅ°¡ µ¿ÀÏÇÒ °Í. µ¿ÀÏÇÑ ÆĶó¹ÌÅ͸¦ °¡Áú °Í. µ¿ÀÏÇÑ »óÀ§¼öÁØ È®Àå»óÅ¿¡ ÀÖÀ» °Í.

\let\boxhor=\hbox \ifx\boxhor\hbox %is true
\font\a=cmr10 \font\b=cmr10 \ifx\a\b %is true

\ifx\commandsfile\undefined\else\endinput\fi
\let\commandsfile\null

¸í·ÉÀ» È®ÀåÇÏÁö ¾Ê´Â´Ù´Â °ÍÀº, À§¿¡ º¸ÀÎ \if¿¡¼­ÀÇ ¿¹¿Í À¯»çÇÏ°Ô
\def\pion#1{$\ifx#1+\pi^+\else\pi^-\fi$}
·Î Á¤ÀÇÇÑ ´ÙÀ½
\def\a{+}
\pion\a
ÇÑ °á°ú´Â, \if¿¡¼­¿Í´Â ´Þ¸® $\pi^-$ °¡ µÈ´Ù. Áï, \a¸¦ +·Î È®ÀåÇÏÁö ¾Ê¾ÒÀ¸¹Ç·Î \ifx Á¶°Ç¹®ÀÇ °ªÀº °ÅÁþ(false)ÀÌ µÇ°í, ±× °á°ú \else\pi^-°¡ ½ÇÇàµÈ °ÍÀÌ´Ù.

1.4 Mode °Ë»ç(\ifhmode,\ifvmode,\ifmmode)

\ifhmode is true if TEX is in HorizontalMode or restricted horizontal mode. • \ifvmode is true if TEX is in VerticalMode or internal vertical mode. • \ifmmode is true if TEX is in MathMode or display math mode.

1.5 Number °Ë»ç(\ifnum, \ifodd)

\ifnum<number1><relation><number2>
<relation>Àº $>, =, <$ °¡¿îµ¥ ÇϳªÀÌ´Ù.(catcode 12)

\ifodd<number>
is true if the <number> is odd.

1.6 Dimension °Ë»ç(\ifdim)

\ifdim<dimen>
»ç¿ë¹ýÀº \ifnum°ú °°Áö¸¸ ¼ýÀÚ°¡ ¾Æ´Ñ ±æÀ̺¯¼ö°¡ ¿Â´Ù.

1.7 Box °Ë»ç(\ifvoid, \ifhbox, \ifvbox)

Contents of box registers can be tested with
\ifvoid<8-bit number>
which is true if the register contains no box,

\ifhbox<8-bit number>
which is true if the register contains a horizontal box, and

\ifvbox<8-bit number>
which is true if the register contains a vertical box.

1.8 ÆÄÀÏ °Ë»ç(\ifeof)

ÀÔ·ÂÆÄÀÏÀÇ EOF »óŸ¦ °Ë»çÇÑ´Ù. \ifeof<number> ÇüÅ·Π¾²À̸ç, <number>°¡ 0-15À̸é falseÀÌ´Ù. ÀÌ ¸í·ÉÀ» ÀÌ¿ëÇÏ¿© ÆÄÀÏÀÌ Á¸ÀçÇÏ´ÂÁö °Ë»çÇÒ ¼ö ÀÖ´Ù.
\newread\instream \openin\instream= fname.tex
\ifeof\instream \message{File ¡¯fname¡¯ does not exist!}
\else \closein\instream \input fname.tex
\fi

1.9 \iff :)

$a\iff b$
$$a\iff b$$

1.10 Case¹®(\ifcase)

\ifcase<number><case0>
\or ...
\or<casen>
\else<other cases>
\fi

\ifcaseÀÇ ÀüÇüÀûÀÎ º¸±âÀÌ´Ù.
\def\today{\ifcase\month\or
  January\or  February\or  March\or    April\or
  May\or      June\or      July\or     August\or
  September\or October\or November\or December\fi
\space\number\day, \number\year}

1.11 \newif, \iftrue, \iffalse

\newif »õ·Î¿î Á¶°Ç º¯¼ö¸¦ ¼³Á¤ÇÑ´Ù.
\newif\iffoo
ÀÌ ÇϳªÀÇ ¸í·ÉÀ¸·Î TeXÀº ¼¼ °³ÀÇ ControlSequences¸¦ Á¤ÀÇÇÑ´Ù. Áï, \footrue, \foofalse, \iffoo¸¦ Á¤ÀÇÇÏ´Â °ÍÀÌ´Ù.

\def\footrue{\let\iffoo=\iftrue}
\def\foofalse{\let\iffoo=\iffalse}
\foofalse

\iffoo
 <iftrue_commands>
\else
 <iffalse_commands>
\fi

2 LaTeX2eÀÇ Á¶°Ç¹®

LaTeX2eÀÇ Á¶°Ç¹®Àº TeXÀÇ °æ¿ì¿Í´Â ´Þ¸® ´ë°³ ¼¼ °³ÀÇ ÀÎÀÚ¸¦ °¡Áö´Â Çü½ÄÀ» ÃëÇÑ´Ù. ¿¹ÄÁ´ë
\@ifXXX{condition}{iftrue_execution}{iffalse_execution}
ÀÌ ÀüÇüÀûÀÎ Çü½ÄÀÌ´Ù. ƯÈ÷ ifthen ÆÐÅ°Áö´Â ÀÌ·¯ÇÑ Çü½ÄÀÇ ¸í·ÉÀ» Á»´õ ÀÚÀ¯·Ó°Ô È°¿ëÇÒ ¼ö ÀÖµµ·Ï ÇÑ´Ù.

°¢°¢ÀÇ ÆÐÅ°ÁöµéÀº µ¶ÀÚÀûÀÎ \if Çü½ÄÀ» °®Ãß°í ÀÖ´Â °æ¿ì°¡ ¸¹´Ù. ¿¹¸¦ µé¸é FancyHdr ÆÐÅ°ÁöÀÇ \iffloatpage ¸í·ÉÀÌ ±× ÇÑ º¸±âÀÌ´Ù. See FancyHdr.

2.1 LaTeXÀÇ \newif, \iffalse, \iftrue »ç¿ë

article.clsÀÇ titlepage °ü·Ã ¼³Á¤À» º¸¸é ´ÙÀ½°ú °°´Ù.
\newif\if@titlepage
\@titlepagefalse
\DeclareOption{titlepage}{\@titlepagetrue}
\ProcessOptions

\if@titlepage
....
\else
....
\fi

ÀÌ¿Í µ¿ÀÏÇÑ ±¸¹®¹ýÀ¸·Î ´Ù¸¥ \if@ Çü½ÄÀÇ ¼³Á¤À» ÇÒ ¼ö ÀÖ´Ù. °£´ÜÇÑ ¿¹¸¦ µé¾îº»´Ù.
\newif\if@pdfmake
\@pdfmaketrue
¶ó´Â ÀÓÀÇÀÇ ¼³Á¤À» »õ·Î ÇÏ°Ô µÇ¸é, \@pdfmaketrue¿Í \@pdfmakefalse¸¦ ¼±¾ðÇÒ ¼ö ÀÖ°Ô µÈ´Ù. ÀÌ ÀÌÈķδÂ
\if@pdfmake
...
\else
...
\fi
ÇüÅÂÀÇ TeX Çü½Ä ¸í·ÉÀ» »ç¿ëÇÒ ¼ö ÀÖ´Ù.

±×·¯³ª ÀÌ·± TeX ±¸¹®Çü½ÄÀÇ »ç¿ë¹ýÀº ¹ø°Å·Î¿ï »Ó ¾Æ´Ï¶ó syntax ¿À·ù¸¦ ÀÏÀ¸Å³ °¡´É¼ºÀÌ ³Ê¹« ¸¹¾Æ¼­, ÀÌ °úÁ¤À» LaTeX2e ±¸¹®¹ýÀ¸·Î Æí¸®ÇÏ°Ô Ã³¸®ÇÏ´Â ifthen ÆÐÅ°Áö¸¦ ÀÌ¿ëÇÏ´Â °ÍÀÌ ÁÁ´Ù. ¾Æ·¡ ifthen ÆÐÅ°Áö °ü·Ã ºÎºÐ ÂüÁ¶.

2.2 \@if

LaTeX¿¡¼­ \newif¿Í \@if´Â ´ÙÀ½°ú °°ÀÌ Á¤ÀǵǾî ÀÖ´Ù.
\def\newif#1{%
  \count@\escapechar \escapechar\m@ne
    \let#1\iffalse
    \@if#1\iftrue
    \@if#1\iffalse
  \escapechar\count@}
\def\@if#1#2{%
  \expandafter\def\csname\expandafter\@gobbletwo\string#1%
                    \expandafter\@gobbletwo\string#2\endcsname
                       {\let#1#2}}

2.3 \@ifnextchar

LaTeX¿¡¼­ °¡Àå ¸¹ÀÌ ¾²´Â Á¶°Ç¹® Áß ÇϳªÀÌ´Ù. ÁÖ¾îÁø ¸í·É¿¡ ÇØ´çÇÏ´Â ºÎºÐÀÇ ´ÙÀ½ ÇÑ ±ÛÀÚ¸¦ Àо °Ë»çÇÑ´Ù. ´ÙÀ½ ¿¹´Â \@ifnextchar ¸í·ÉÀ¸·Î Á¦°ö±Ù ±âÈ£¸¦ Á¤ÀÇÇÑ ºÎºÐÀÌ´Ù.
\renewcommand\sqrt{\@ifnextchar[\@sqrt\sqrtsign}
\def\@sqrt[#1]{\root #1\of}

ÀÌ ¸í·ÉÀº \sqrt[3]°ú °°Àº ¸í·ÉÀÌ ÀÖÀ¸¸é \@ifnextchar[°¡ Âü°ª(true)·Î µÇµ¹·ÁÁö¹Ç·Î \@sqrt[3]À» ºÎ¸¥´Ù. ±×·¯³ª \sqrtÀÇ °æ¿ì¿¡´Â \@ifnextchar[°¡ °ÅÁþ(false)À̹ǷΠ\sqrtsign ¸í·ÉÀ» È£ÃâÇÏ°Ô µÈ´Ù.

2.4 \IfFileExists

ÀÌ ¸í·ÉÀº ¼¼ °³ÀÇ ÀÎÀÚ¸¦ °¡Áø´Ù. ù¹ø° °ÍÀº ÆÄÀÏÀ̸§ÀÌ°í, ±× ´ÙÀ½Àº °¢°¢ then°ú else¿¡ ÇØ´çÇϴ ó¸® ¸í·ÉµéÀÌ´Ù. ÆÄÀÏÀÌ Á¸ÀçÇÏ¸é µÎ¹ø° ÀÎÀÚ°¡, Á¸ÀçÇÏÁö ¾ÊÀ¸¸é ¼¼¹ø° ÀÎÀÚ°¡ ½ÇÇàµÈ´Ù. ÆÄÀÏÀÌ Á¸ÀçÇÏ¸é ºÒ·¯µéÀ̵µ·Ï ÇÏ´Â ¸í·ÉÀ¸·Î \InputIfFileExists°¡ ÀÖ´Ù. ¿ª½Ã ¼¼ °³ÀÇ ÀÎÀÚ¸¦ °¡Áö¸ç, ÆÄÀÏÀÌ Á¸ÀçÇÏ¸é ºÒ·¯µéÀÎ ´ÙÀ½, µÎ¹ø° ÀÎÀÚ·Î ÁÖ¾îÁø ¸í·ÉÀ» ½ÇÇàÇÏ°í, ±×·¸Áö ¾ÊÀ¸¸é ¼¼¹ø° ÀÎÀÚ·Î ÁÖ¾îÁø ¸í·ÉÀ» ½ÇÇàÇÑ´Ù.
\newcommand{\printglossary}{%
  \InputIfFileExists{\jobname.gld}{}{%
  \typeout{No file exists! \jobname.gld}}%
}

2.5 \@ifstar

º°Ç¥ºÙÀº ¸í·É(\table*, \section* µî)À» ó¸®Çϱâ À§ÇÑ Å×½ºÆ®.
\def\@ifstar#1{\@ifnextchar *{\@firstoftwo{#1} }}

2.6 \@ifpackageclassloaded, \@ifpackageclasslater, \@ifpackageclasswith

\@ifpackageloaded
To find out if a package has already been loaded.
\@ifpackageloaded{package_name}{then_commands}{else_commands}

\@ifpackagelater
To find out if a package has already been loaded with a version more recent than _version_.
\@ifpackagelater{package_name}{_version_}{then_commands}{else_commands}

\@ifpackagewith
To find out if a package has already been loaded with at least the options _options_.
\@ifpackagewith{package_name}{_options_}{then_commands}{else_commands}

2.7 ifthen ÆÐÅ°Áö

ifthen ÆÐÅ°Áö´Â David Carlisle¾¾°¡ ¸¸µç °ÍÀ¸·Î, Á¶°Ç¹® 󸮸¦ ¿ëÀÌÇÏ°Ô ÇØÁÖ´Â ¿ªÇÒÀ» ÇÑ´Ù.

2.7.1 \ifthenelse ¸í·É

\ifthenelse{<test>}{<then clause>}{<else clause>}
<test>¸¦ boolean ÇÔ¼ö·Î º¸°í °Ë»çÇÏ¿©, ÂüÀ̸é <then clause>¸¦, °ÅÁþÀ̸é <else clause>¸¦ ½ÇÇàÇÑ´Ù.

calc ÆÐÅ°Áö¿Í ÇÔ²² ½á¼­ am-pm Çü½ÄÀ» ¹Ù²Ù´Â ±¸¹®À» ÀÛ¼ºÇغ»´Ù.
<!> calc ÆÐÅ°Áö¿¡ ´ëÇؼ­´Â TeX»ê¼ú¿¬»êÀ» º¼ °Í.
\usepackage{ifthen,calc} %% preamble

\newcommand{\printtime}{%
  \setcounter{hours}{\time / 60}%
  \setcounter{minutes}{\time - \value{hours} * 60}%
  \ifthenelse{\value{hours}>12}%
   {\setcounter{hours}{\value{hours} - 12}%
    \thehours:\theminutes\,pm\ \today}%
   {\thehours:\theminutes\,am\ \today}
}

2.7.2 \ifthenelse¿¡¼­ ¾²ÀÌ´Â Á¶°Ç °Ë»ç

\ifthenelseÀÇ Ã¹¹ø° ÀÎÀÚ¿¡ ¿À´Â Á¶°Ç °Ë»ç¸¦ À§Çؼ­´Â ´ÙÀ½°ú °°Àº Çü½ÄÀÌ ¾²ÀÏ ¼ö ÀÖ´Ù.
  1. ³í¸®¿¬»ê
    • \and
    • \or
    • \not
    • °ýÈ£ \( \)
  2. ¼ýÀÚ ºñ±³
    • number $$<$$ number
    • number $$=$$ number
    • number $$>$$ number
    • \isodd{number}
  3. commands ºñ±³
    • \isundefined{command name}
    • \equal{string}{string}
  4. ±æÀ̺¯¼ö ºñ±³
    • \lengthtest{dimen $$<$$ dimen}
    • \lengthtest{dimen $$=$$ dimen}
    • \lengthtest{dimen $$>$$ dimen}
  5. boolean °Ë»ç
    • \boolean{name}

\equal¸í·ÉÀ¸·Î °Ë»çÇÏ´Â <string>Àº tokenÀ¸·Î È®ÀåµÈ ¸í·É¾îµéÀÌ´Ù. ¸í·ÉÀ» È®ÀåÇÑ °á°ú°¡ µ¿ÀÏ(equal)Çϸé ÀÌ Á¶°ÇÀº Âü(true)ÀÌ µÈ´Ù. \isodd ¸í·ÉÀº <number>°¡ Ȧ¼öÀ̸é ÂüÀÌ µÈ´Ù. ÀÎÀÚ°¡ ¼ýÀÚ°¡ ¾Æ´Ï°Å³ª Ȧ¼ö°¡ ¾Æ´Ï¸é °ÅÁþ(false)ÀÌ´Ù. \isundefined{\cmd}´Â \cmd°¡ Á¤ÀǵǾî ÀÖÁö ¾ÊÀ» ¶§ ÂüÀÌ´Ù. \boolean{xyz} ¸í·ÉÀº TeXÀÇ ¿ø½Ã \if¹®¿¡ ÀÇÇØ Á¤ÀÇµÈ \ifxyz°¡ \iftrueÀÏ ¶§ Âü(true) °ªÀ» µÇµ¹·ÁÁØ´Ù.
xyz´Â \newboolean ¶Ç´Â \provideboolean¿¡ ÀÇÇÏ¿© Á¤ÀÇµÉ ¼ö ÀÖ´Ù. ±×¸®°í, TeXÀÇ \newif¿¡ ÀÇÇÏ¿© Á¤ÀÇµÈ ÅäÅ«¿¡ ´ëÇؼ­µµ ¾µ ¼ö ÀÖ´Ù. ¿¹¸¦ µé¸é, \boolean{true}´Â \iftrue¸¦ °¡¸®Å°´Â °ÍÀÌ´Ù. ¶Ç, \boolean{mmode}´Â \ifmmode¿Í °°´Ù.

2.7.3 \newboolean, \setboolean

\usepackage{ifthen}  %% preamble

\newboolean{BoolVar}
\setboolean{BoolVar}{true}
\ifthenelse{\boolean{BoolVar}}{1}{2}

ÀÌ Çü½ÄÀ» ÀÌ¿ëÇÏ¿©, ¾Õ¼­ \@pdfmake¸¦ ¼³Á¤Çß´ø ¹æ½Ä¿¡ ÀÀ¿ëÇغ¸ÀÚ. ¸ÕÀú, @pdfmake¶ó´Â ºÒ¸° º¯¼ö¸¦ ¸¸µé°í true °ªÀ» ÇÒ´çÇÑ´Ù.
\newboolean{@pdfmake}
\setboolean{@pdfmake}{true}
ÀÌÁ¦ \ifthenelse Á¶°Ç¹®À» ¾´´Ù.
\ifthenelse{\boolean{@pdfmake}}%
 {.....} % if true
 {.....} % if false

3 etoolboxÀÇ Á¶°Ç¹®

etoolbox´Â e-TeXÀÇ primitive¸¦ ÀÌ¿ëÇÏ´Â ´Ù¾çÇÑ ¸í·ÉÀ» Á¦°øÇÑ´Ù. Á¶°Ç °Ë»ç¿Í °ü·ÃÇؼ­ ÇÊ¿äÇÑ °ÍÀÌ °ÅÀÇ ´Ù ÀÖ´Ù½ÃÇÇÇÒ Á¤µµÀ̹ǷΠÀÚ¼¼ÇÑ °ÍÀº etoolbox ¹®¼­¸¦ Âü°íÇÒ °Í. ¿©±â¼­´Â boolean °ü·ÃµÈ °Í°ú Á¶°Ç¹® µÎ¾î °³¸¸À» ¼Ò°³ÇÑ´Ù. Á¶°Ç¿¡ µû¸¥ ½ÇÇàÀº LaTeX Á¶°Ç¹®ÀÇ ¹®¹ýÀ» µû¸¥´Ù.

3.1 boolean

  • \newbool{name}
  • \providebool{name}
  • \setbool{name}{value} : value´Â true³ª false.
  • \booltrue{name}
  • \boolfalse{name}
  • \ifbool{name}{true}{false}
  • \notbool{name}

3.2 Á¶°Ç °Ë»ç

control sequences
  • \ifdef{controlsequence}{true}{false}, \ifcsdef{name}{true}{false}
  • \ifundef{controlsequence}{true}{false}, \ifcsundef{name}{true}{false}
  • \ifdefequal{controlsequence}{controlsequence}{true}{false}, \ifcsequal{name}{name}{true}{false}
string
  • \ifstrequal{string}{string}{true}{false}
  • \ifstrempty{string}{true}{false}
  • \ifblank{string}{true}{false}
arithmetic
  • \ifnumcomp{integer}{relation}{integer}{true}{false} : integer´Â e-TeXÀÇ number expression ¾µ ¼ö ÀÖÀ½.
  • \ifnumequal{integer}{integer}{true}{false}
  • \ifnumgreater, \ifnumless
  • \ifnum.... ²ÃÀÇ ¸í·É¿¡ »ó´çÇÏ´Â \ifdim... ¸í·ÉµéÀÌ ÀÖÀ½.
  • \ifnumodd

4 Loop

4.1 PlainTeXÀÇ \loop \repeat

\newcount\MyCount
\MyCount=0
\newcount\Summation
\Summation=0
\loop
 \message{\number\MyCount}
 \advance\MyCount by 1
 \advance\Summation by \MyCount
  \hbox{MyCounter Number: \number\MyCount\quad Summatioin: \number\Summation}
\ifnum\MyCount<10\repeat
\bye

4.2 ifthen ÆÐÅ°ÁöÀÇ \whiledo

\whiledo{<test>}{<while clause>}
<test>´Â À§¿¡¼­ ¾ð±ÞÇÑ Á¶°Ç°Ë»ç¿Í µ¿ÀÏÇÑ ±¸¹®À» »ç¿ëÇÑ´Ù. ÀÌ Á¶°ÇÀÌ trueÀÎ ÇÑ <while clause>°¡ ½ÇÇàµÈ´Ù.

1ºÎÅÍ 10±îÁö ´õÇÏ¿© ÇÕÀ» Ãâ·ÂÇغ»´Ù.
\documentclass{article}
\usepackage{ifthen,calc}
\usepackage{hfont}

\begin{document}

\newcounter{myloopcnt}
\setcounter{myloopcnt}{0}
\newcounter{summation}
\setcounter{summation}{0}

\noindent\textbf{1ºÎÅÍ 10±îÁö ´õÇغ»´Ù.}

\noindent\whiledo{%
        \value{myloopcnt} < 10}{%
        \stepcounter{myloopcnt}%
        \setcounter{summation}{\thesummation + \themyloopcnt}%
        \themyloopcnt¹ø° ½ÇÇà : \qquad ÇöÀç±îÁö ÇÕ°è \thesummation\\}
\end{document}

4.3 \for-loop

\makeatletter
\def\for#1#2#3{\@ifnextchar[{\@for@{#1}{#2}{#3}}{\@for@{#1}{#2}{#3}[1]}}
\long\def\@for@#1#2#3[#4]#5{\setcounter{#1}{#3}\addtocounter{#1}{1}%
        \edef\for@loopend{\arabic{#1}}%
        \setcounter{#1}{#2}%
        \loop
        \ifnum \expandafter\the\csname c@#1\endcsname < \for@loopend\relax
        #5\addtocounter{#1}{#4}\repeat}
\newcounter{repeatcnt}
\makeatother

°°Àº ±â´ÉÀ» ÀÌ \for ¹®À» ½á¼­ ±¸ÇöÇغ¸ÀÚ. ¿©±â¼­´Â ifthen ÆÐÅ°Áö°¡ ºÒÇÊ¿äÇÏ´Ù.
\documentclass{article}
\usepackage{calc}
\usepackage{hfont}

\makeatletter
\def\for#1#2#3{\@ifnextchar[{\@for@{#1}{#2}{#3}}{\@for@{#1}{#2}{#3}[1]}}
\long\def\@for@#1#2#3[#4]#5{\setcounter{#1}{#3}\addtocounter{#1}{1}%
        \edef\for@loopend{\arabic{#1}}%
        \setcounter{#1}{#2}%
        \loop
        \ifnum \expandafter\the\csname c@#1\endcsname < \for@loopend\relax
        #5\addtocounter{#1}{#4}\repeat}
\newcounter{repeatcnt}
\makeatother

\begin{document}

\newcounter{summation}
\setcounter{summation}{0}

\noindent\textbf{1ºÎÅÍ 10±îÁö ´õÇغ»´Ù.}

\noindent
\for{repeatcnt}{1}{10}%
        {\setcounter{summation}{\thesummation + \therepeatcnt}%
         \therepeatcnt¹ø° ½ÇÇà : \qquad ÇöÀç±îÁö ÇÕ°è \thesummation\\}

\end{document}

4.4 multido

Timothy van Zandt ¾¾°¡ ÀÛ¼ºÇÑ ¸ÅÅ©·ÎÀÌ´Ù. multido.tex°ú multido.sty·Î »ç¿ëÇÒ ¼ö ÀÖ´Ù.
PSTricks ¸ÅÅ©·Î´Â ÀÌ ½ºÅ¸ÀÏÀ» ÀÚµ¿À¸·Î ºÒ·¯µéÀδÙ.
\multido{_variables_}{_repetitions_}{_stuff_}
¿©±â¼­ _variables_Àº ´ÙÀ½ Çü½ÄÀ¸·Î ¾²ÀδÙ.
variable = initial value + increment
variable·Î ¿Ã ¼ö ÀÖ´Â °ÍÀº Dimension, Number, Integer, RealÀÌ°í °¢°¢ \d, \n, \i, \r µîÀ¸·Î Çü½ÄÀ» Áö½ÃÇÑ´Ù. ´ÙÀ½ ¿¹¸¦ º¸¶ó.
\multido{}{10}{\TeX\ }

\multido{\d=2pt+3pt}{5}{\d, }

\multido{\n=2+3}{10}{\n, }

\multido{\i=2+-3}{10}{\i, }

\multido{\r=2+3.05}{6}{\r, }

  • \multido ¸í·ÉÀº nestingÀÌ °¡´ÉÇÏ´Ù.
  • ½ÇÇàÀü¿¡ Ä«¿îÅ͸¦ 1¾¿ Áõ°¡½ÃÅ°´Â \mmultido ¸í·Éµµ ÀÖ´Ù.
  • \multidostopÀº multido ¹Ýº¹¹®À» ÇöÀç À§Ä¡¿¡¼­ °­Á¦·Î ºüÁ®³ª°¡°Ô ÇÑ´Ù.

5 ÀÀ¿ë : Á¶°ÇºÎ ÄÄÆÄÀÏ

5.1 TTY¸¦ ÅëÇÏ¿© »ç¿ëÀÚ ÀÔ·ÂÀ» ¹Þ¾ÆµéÀÌ´Â ¹æ¹ý

main.tex ÆÄÀÏÀ» ÄÄÆÄÀÏ ½ÃµµÇϸé È­¸é¿¡ "Yes/No"¸¦ ¹¯°í, y ¶Ç´Â n·Î ´äÇÏ´Â µ¥ µû¶ó¼­ ´Ù¸¥ °á°ú¸¦ º¸¿©ÁÖ´Â °£´ÜÇÑ ¼Ò½º¸¦ ÀÛ¼ºÇغ¸ÀÚ. ÇÑ±Û Å͹̳ÎÀÏÁö ¾Ë ¼ö ¾øÀ¸¹Ç·Î È­¸é»óÀÇ ÀÀ´äÀº ¿µ¹®À¸·Î ÇÏ´Â °ÍÀ¸·Î ÇÑ´Ù.

\documentclass{article}
\usepackage{hfont}
\usepackage{ifthen}

¿©±â¿¡¼­ºÎÅÍ Preamble ¼³Á¤À» ½ÃÀÛÇÑ´Ù. ttyin, ttyoutÀ» Á¤ÀÇÇÏ°í \Msg ¸í·É°ú \Ask ¸í·ÉÀ» Á¤ÀÇÇÑ´Ù.
\makeatletter
\chardef\ttyin16
\chardef\ttyout16
\def\iden#1{#1}
\def\strip#1#2 \@gobble{\def #1{#2}}
\def\@defpar{\par}
\def\yes{yes}
\def\y{y}
\def\n{n}

\def\Msg{\immediate\write\ttyout}
\def\Ask#1#2{%
    \message{#2}\read\ttyin to #1\ifx#1\@defpar\def#1{}\else
    \iden{\expandafter\strip
       \expandafter#1#1\@gobble\@gobble} \@gobble\fi}
\makeatother

»ç¿ëÀÚ ÀÎÅÍÆäÀ̽º¸¦ À§ÇÑ YesOrNo¶ó´Â boolean º¯¼ö(ÀÌ°ÍÀ» ¾²·Á¸é ifthen ÆÐÅ°Áö°¡ ÇÊ¿äÇÏ´Ù.)¸¦ ¼³Á¤ÇÑ´Ù. ±âº»°ªÀº true.
\newboolean{YesOrNo}
\setboolean{YesOrNo}{true}

º»¹® ½ÃÀÛ.
\begin{document}

È­¸é¿¡ "Please Answer Me, Yes or No(y/n)?"À̶ó´Â ¸Þ½ÃÁö¸¦ º¸¿©ÁÖ°í »ç¿ëÀÚ ÀÔ·ÂÀ» ¹Þ¾ÆµéÀδÙ.
\Msg{**************************************************^^J%
     * Please Answer Me, Yes or No(y/n)?}%
\Ask\answer{%
     **************************************************}%

¸¸¾à y°¡ ÀԷµǸé YesOrNo¸¦ true·Î, ±×¹ÛÀÇ °æ¿ì¿¡´Â ¸ðµÎ false·Î ¼³Á¤
\ifx\y\answer\setboolean{YesOrNo}{true}
\else\setboolean{YesOrNo}{false}\fi

Ãâ·Â·çƾ. YesOrNo°¡ trueÀÎÁö falseÀÎÁö¿¡ µû¶ó ´Ù¸¥ ¸Þ½ÃÁö¸¦ DVI·Î Ãâ·ÂÇÑ´Ù. ifthen ÆÐÅ°ÁöÀÇ \ifthenelse ¸í·ÉÀ» »ç¿ëÇÔ.
\ifthenelse{\boolean{YesOrNo}}%
        {`¿¹½º'¸¦ ¼±ÅÃÇϼ̽À´Ï´Ù.}%
        {`³ë'¸¦ ¼±ÅÃÇϼ̽À´Ï´Ù.}

¹®¼­ ³¡.
\end{document}

5.2 ¸í·ÉÇàÀ» ÀÌ¿ëÇÏ´Â ¹æ¹ý

°°Àº ÀÏÀ» ¸í·ÉÇà¿¡¼­ ÇѲ¨¹ø¿¡ ÇÏ´Â ¹æ¹ýÀº ¾øÀ»±î? ±× °¡¿îµ¥ °¡Àå ½¬¿î ¹æ¹ýÀ» »ý°¢Çغ¸ÀÚ.

¿øº»À» ´ÙÀ½°ú °°ÀÌ ÀÛ¼ºÇÑ´Ù.
\documentclass{article}
\usepackage{hfont}
\usepackage{ifthen}

\makeatletter
\chardef\ttyin16
\chardef\ttyout16
\def\iden#1{#1}
\def\strip#1#2 \@gobble{\def #1{#2}}
\def\@defpar{\par}
\def\Ask#1#2{%
    \message{#2}\read\ttyin to #1\ifx#1\@defpar\def#1{}\else
    \iden{\expandafter\strip
       \expandafter#1#1\@gobble\@gobble} \@gobble\fi}
\def\Msg{\immediate\write\ttyout}
\def\yes{yes}
\def\y{y}
\def\n{n}
\makeatother

\newboolean{YesOrNo}
\setboolean{YesOrNo}{true}

\def\getYesOrNo{%
        \Msg{**************************************************^^J%
         * Please Answer Me, Yes or No(y/n)?}%
        \Ask\answer{%
         **************************************************}%
}

\newcommand\DetermineYesOrNo{%
%% ¸¸¾à \answer°¡ ÀÌ¹Ì ÁÖ¾îÁ®ÀÖÁö ¾Ê´Ù¸é
\ifx\answer\undefined
        \getYesOrNo
\else\fi
%% \answer¿¡ µû¶ó YesOrNo ºÒ¸°°ªÀ» °áÁ¤ÇÔ
\ifx\y\answer\setboolean{YesOrNo}{true}
        \else\setboolean{YesOrNo}{false}\fi
}

%%% Ãâ·Â¹®ÀÚ¿­
\newcommand\YesMessage{`¿¹½º'¸¦ ¼±ÅÃÇϼ̽À´Ï´Ù.}
\newcommand\NoMessage{`³ë'¸¦ ¼±ÅÃÇϼ̽À´Ï´Ù.}

\begin{document}
\DetermineYesOrNo
\ifthenelse{\boolean{YesOrNo}}%
        {\YesMessage}%
        {\NoMessage}

\end{document}

¸í·ÉÇà¿¡¼­´Â ´ÙÀ½°ú °°ÀÌ Ã³¸®ÇÑ´Ù.(ÆÄÀÏÀ̸§Àº test.tex)
#> latex \def\answer{y}\input{test}

YesOrNo¸¦ no·Î ÇÏ°í ½ÍÀ¸¸é
#> latex \def\answer{n}\input{test}

¸¸¾à ´Ü¼øÇÏ°Ô latex test¸¸À» ½ÇÇàÇÑ´Ù¸é ¾Õ¼­¿Í °°Àº ´ëÈ­½ÄÀ¸·Î (y/n)À» È­¸é¿¡¼­ ¹°¾î¼­ ¾ò´Â´Ù. ÀÌ°ÍÀ» ¹èÄ¡ÆÄÀÏ ¶Ç´Â ½ºÅ©¸³Æ®·Î ½ÇÇàÇÒ ¼ö ÀÖÀ» °ÍÀÌ´Ù.


¾ÕºÎºÐÀº Victor Eijkhout, TeX By Topic(http://www.eijkhout.net/tbt/), pp.112-117. ¿¡¼­ ÁÖ·Î ¹ßÃé, ÀοëÇÏ¿´½À´Ï´Ù.
DeleteMe ÀÌ ºÐ ¼ºÇÔÀ» ¿ìÂî ÀÐÁö¿ä? --Karnes My name is approximately pronounced "ike-howt". -- Victor Eijkhout HJhan

DeleteMe \ifXXX °°Àº °ÍÀÌ ¸¹ÀÌ »ç¿ëµÇ´øµ¥ ÀÚ¼¼ÇÑ ¼³¸íÀ» ¸ø ã¾Ò½À´Ï´Ù. ;) °í¼ö´ÔµéÀÇ ¼³¸íÀ» µé¾úÀ¸¸é ÇÕ´Ï´Ù. --2004-03-28hermian

DeleteMe À¯¿ëÇÑ ÆäÀÌÁö ÀÛ¼ºÇØÁֽɿ¡ °¨»çÀÇ ¸»¾¸ µå¸³´Ï´Ù. LaTeXÀ» ¾²·Á¸é ÄÄÇ»Å͵µ Á» ¾Ë¾Æ¾ßÇÏ°í, ¼öÇеµ, ÆùÆ®µµ Á» ¾Ë¾Æ¾ßÇÏ°í, ÆíÁýµµ Á¶±Ý ¾Ë¸é ÁÁ°í... ±×·¯³ª °á±¹ ÀÌ ConditionalsÀ» ¾Ë¾Æ¾ß °¡Àå È¿À²ÀûÀÎ ¹®¼­ÀÛ¼ºÀ» ÇÒ ¼ö ÀÖÀ¸¸®¶ó´Â »ý°¢À» Áö¿ï ¼ö ¾ø½À´Ï´Ù. --Progress
°í¸¿½À´Ï´Ù. ;) À̵û±Ý ĪÂù¹Þ±¸ ½ÍÀ» ¶§µµ ÀÖ´ä´Ï´Ù. ´¥¶ì¹Ì Ç߰ŵ¢¿ä. :) µµ¿òÀÌ µÇ¸é ÁÁ°Ú½À´Ï´Ù. --Karnes
±×³É ÆäÀÌÁö¸¸ ´ú·· ¸¸µé¾ú´õ´Ï ³¯¸¶´Ù ¹«·°¹«·°ÀÚ¶ó´Â±º¿ä . Àß°¡²Ù¾î ÁֽŠKarnes´Ô °¨»çÇÕ´Ï´Ù. ´¥¶ì¹Ì °¡ ¾Ð±ÇÀÔ´Ï´Ù. :) ¿­½ÉÈ÷ °øºÎÇÏ°Ú½À´Ï´Ù. ~²Ù¹÷ --hermian

Contributors: Karnes


^
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2011-07-05 18:40:17
Processing time 0.1606 sec