KTUGFaq
KTUG FAQ
Beware of friends who are false and deceitful.
FrontPage › Conditionals
[ÆíÁý]
1 TeXÀÇ Á¶°Ç¹® ¶
TeXÀÇ if Á¶°Ç¹®Àº ÁÖ·Î ¹®ÀÚ¿Í ControlSequences¸¦ °Ë»çÇϱâ À§ÇÏ¿© »ç¿ëµÈ´Ù.
±¸¹®¹ýÀº ´ÙÀ½°ú °°´Ù.
\if... \fi \if... \else... \fi
[ÆíÁý]
1.1 \if ¶
TeXÀº \if ´ÙÀ½¿¡ ³ª¿À´Â ¸ÅÅ©·ÎµéÀ» Àü°³Çϴµ¥, ¾ðÁ¦±îÁö Çϳĸé Àü°³ÇÒ ¼ö ¾ø´Â ÅäÅ«À» Á¤È®È÷ µÎ °³ ¾òÀ» ¶§±îÁö ÇÑ´Ù. ±×¸®°í³ª¼ ±× ¾ò¾îÁø µÎ °³ÀÇ ÅäÅ«À» ºñ±³ÇÑ´Ù. µû¶ó¼ \if¸¦ ÀÌ¿ëÇؼ ºñ±³ÇÒ ´ë»óÀÌ Àü°³ °¡´ÉÇÑ ¸ÅÅ©·Î³ª ¾×Ƽºê ¹®ÀÚÀÌ¸é ±×°Íµé ¾Õ¿¡ \noexpand¸¦ ºÙ¿©¼ Àü°³¸¦ ¸·°í ºñ±³¸¦ ÇؾßÇÑ´Ù. ¿¹¸¦µé¾îº¸ÀÚ.
À§ÀÇ Á¶°Ç¹®ÀÇ °á°ú´Â °ÅÁþÀÌ´Ù. ¿Ö³ÄÇϸé, À§ÀÇ ¼³¸í´ë·Î \if ´ÙÀ½¿¡ ³ª¿À´Â ¸ÅÅ©·Î¸¦ Àü°³Çϴµ¥, ¿©±â¼´Â \A¸¦ Àü°³ÇϰԵȴÙ. ±×·±µ¥
\A¸¦ Àü°³ÇÏ°í³ª¸é \if abc°¡ µÇ°í, ¹®ÀÚ ÅäÅ« a, b ÀÌ¹Ì µÎ°³ÀÇ Àü°³ÇÒ ¼ö ¾ø´Â ÅäÅ«À» ¾ò¾úÀ¸¹Ç·Î ´õÀÌ»óÀÇ Àü°³¸¦ ¸¶Ä¡°í ±× µÎ°³ÀÇ ÅäÅ«À» ºñ±³ÇÑ´Ù. µû¶ó¼ \if abÀÇ °á°ú°¡ ÀÌ Á¶°Ç¹®ÀÇ °ªÀÌ µÇ´Âµ¥, ´ç¿¬È÷ a ¿Í b´Â ´Ù¸£¹Ç·Î °ÅÁþÀÌ´Ù.
À§ °æ¿ì´Â ¾î¶³±î? ¾Õ¿¡¼ ÇÑ°Í Ã³·³ Çϸé \if\A\B ´Â °á°úÀûÀ¸·Î \if aa À̹ǷΠÀÌ Á¶°Ç¹®ÀÇ °ªÀº ÂüÀÌ´Ù. ´Ù¸¥ ¿¹¸¦ Çϳª ´õ µé¾îº¸ÀÚ.
\if expands the tokens, therefore,
would give the same result as \pion+.
\def\A{abc} \def\B{abc} \if\A\B
\def\A{aaa} \def\B{bbb} \if\A\B
\def\pion#1{$\if#1+\pi^+\else\pi^-\fi$}
\let\a+ \pion\a
[ÆíÁý]
1.2 \ifcat ¶
The \if test ignores CategoryCodes; these can be tested by
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.
\ifcat<token1><token2>
[ÆíÁý]
1.3 \ifx ¶
°¡Àå ¸¹ÀÌ ¾²´Â \if °ü·Ã ¹®¹ý ÁßÀÇ Çϳª. \ifx<token1><token2>´Â µÎ °³ÀÇ tokenÀÌ ÀÏÄ¡ÇÏ´ÂÁö °Ë»çÇÑ´Ù. ±×·¯³ª ¸í·ÉÀ» È®ÀåÇÏÁö´Â ¾Ê´Â´Ù.
ÀÌ Á¶°ÇÀÌ Âü(true)ÀÌ µÇ·Á¸é ´ÙÀ½ Áß ¾î´À Çϳª¿©¾ß ÇÑ´Ù.
- µÎ °³ÀÇ tokenÀÌ ¸í·ÉÀÌ ¾Æ´Ò °Í. µ¿ÀÏÇÑ ¹®ÀÚÄÚµå¿Í CategoryCode¸¦ °¡Áö°Å³ª µ¿ÀÏÇÑ TeX ¿ø½Ã¸í·ÉÀ̰ųª µ¿ÀÏÇÑ \font, \chardef, \countdef¿¡ ÀÇÇØ Á¤ÀÇµÈ °ÍÀÏ °Í.
- µÎ °³ÀÇ 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¿¡¼ÀÇ ¿¹¿Í À¯»çÇÏ°Ô
·Î Á¤ÀÇÇÑ ´ÙÀ½
ÇÑ °á°ú´Â, \if¿¡¼¿Í´Â ´Þ¸® °¡ µÈ´Ù. Áï, \a¸¦ +·Î È®ÀåÇÏÁö ¾Ê¾ÒÀ¸¹Ç·Î \ifx Á¶°Ç¹®ÀÇ °ªÀº °ÅÁþ(false)ÀÌ µÇ°í, ±× °á°ú \else\pi^-°¡ ½ÇÇàµÈ °ÍÀÌ´Ù.
\def\pion#1{$\ifx#1+\pi^+\else\pi^-\fi$}
\def\a{+} \pion\a
[ÆíÁý]
1.5 Number °Ë»ç(\ifnum, \ifodd) ¶
\ifnum<number1><relation><number2>
<relation>Àº °¡¿îµ¥ ÇϳªÀÌ´Ù.(catcode 12)
\ifodd<number>
is true if the <number> is odd.
[ÆíÁý]
1.7 Box °Ë»ç(\ifvoid, \ifhbox, \ifvbox) ¶
Contents of box registers can be tested with
which is true if the register contains no box,
\ifvoid<8-bit number>
\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.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 »õ·Î¿î Á¶°Ç º¯¼ö¸¦ ¼³Á¤ÇÑ´Ù.
ÀÌ ÇϳªÀÇ ¸í·ÉÀ¸·Î TeXÀº ¼¼ °³ÀÇ ControlSequences¸¦ Á¤ÀÇÇÑ´Ù. Áï, \footrue, \foofalse, \iffoo¸¦ Á¤ÀÇÇÏ´Â °ÍÀÌ´Ù.
\newif\iffoo
\def\footrue{\let\iffoo=\iftrue} \def\foofalse{\let\iffoo=\iffalse} \foofalse
\iffoo <iftrue_commands> \else <iffalse_commands> \fi
[ÆíÁý]
2 LaTeX2eÀÇ Á¶°Ç¹® ¶
LaTeX2eÀÇ Á¶°Ç¹®Àº TeXÀÇ °æ¿ì¿Í´Â ´Þ¸® ´ë°³ ¼¼ °³ÀÇ ÀÎÀÚ¸¦ °¡Áö´Â Çü½ÄÀ» ÃëÇÑ´Ù. ¿¹ÄÁ´ë
ÀÌ ÀüÇüÀûÀÎ Çü½ÄÀÌ´Ù. ƯÈ÷ ifthen ÆÐÅ°Áö´Â ÀÌ·¯ÇÑ Çü½ÄÀÇ ¸í·ÉÀ» Á»´õ ÀÚÀ¯·Ó°Ô È°¿ëÇÒ ¼ö ÀÖµµ·Ï ÇÑ´Ù.
\@ifXXX{condition}{iftrue_execution}{iffalse_execution}
°¢°¢ÀÇ ÆÐÅ°ÁöµéÀº µ¶ÀÚÀûÀÎ \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@ Çü½ÄÀÇ ¼³Á¤À» ÇÒ ¼ö ÀÖ´Ù. °£´ÜÇÑ ¿¹¸¦ µé¾îº»´Ù.
¶ó´Â ÀÓÀÇÀÇ ¼³Á¤À» »õ·Î ÇÏ°Ô µÇ¸é, \@pdfmaketrue¿Í \@pdfmakefalse¸¦ ¼±¾ðÇÒ ¼ö ÀÖ°Ô µÈ´Ù.
ÀÌ ÀÌÈķδÂ
ÇüÅÂÀÇ TeX Çü½Ä ¸í·ÉÀ» »ç¿ëÇÒ ¼ö ÀÖ´Ù.
\newif\if@pdfmake \@pdfmaketrue
\if@pdfmake ... \else ... \fi
±×·¯³ª ÀÌ·± 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.
\@ifpackagelater
\@ifpackageloaded{package_name}{then_commands}{else_commands}
To find out if a package has already been loaded with a version more recent than _version_.
\@ifpackagewith
\@ifpackagelater{package_name}{_version_}{then_commands}{else_commands}
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ÀÇ Ã¹¹ø° ÀÎÀÚ¿¡ ¿À´Â Á¶°Ç °Ë»ç¸¦ À§Çؼ´Â ´ÙÀ½°ú °°Àº Çü½ÄÀÌ ¾²ÀÏ ¼ö ÀÖ´Ù.
- ³í¸®¿¬»ê
- \and
- \or
- \not
- °ýÈ£ \( \)
- ¼ýÀÚ ºñ±³
- number number
- number number
- number number
- \isodd{number}
- commands ºñ±³
- \isundefined{command name}
- \equal{string}{string}
- ±æÀ̺¯¼ö ºñ±³
- \lengthtest{dimen dimen}
- \lengthtest{dimen dimen}
- \lengthtest{dimen dimen}
- boolean °Ë»ç
- \boolean{name}
- \boolean{name}
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.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}
- \ifstrequal{string}{string}{true}{false}
- \ifstrempty{string}{true}{false}
- \ifblank{string}{true}{false}
- \ifnumcomp{integer}{relation}{integer}{true}{false} : integer´Â e-TeXÀÇ number expression ¾µ ¼ö ÀÖÀ½.
- \ifnumequal{integer}{integer}{true}{false}
- \ifnumgreater, \ifnumless
- \ifnum.... ²ÃÀÇ ¸í·É¿¡ »ó´çÇÏ´Â \ifdim... ¸í·ÉµéÀÌ ÀÖÀ½.
- \ifnumodd
[ÆíÁý]
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 + incrementvariable·Î ¿Ã ¼ö ÀÖ´Â °ÍÀº 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.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
Contributors: Karnes