|
直引號'在LaTeX中預設是右引號。在LaTeX中可以修改它,使它交替輸出左引號、右引號
- \documentclass{article}
- \newcount\quoteCount
- \quoteCount=0
- \let\rightquote='
- \catcode`'=13 % Make ' an active character
- \def'{%
- \ifodd\quoteCount
- \rightquote%
- \else
- `%
- \fi
- \advance\quoteCount by 1
- }
- \begin{document}
- Hello, 'world'!
- Hello, 'world'!
- \end{document}
复制代码
效果:
Hello, ‘world’!
Hello, ‘world’!
上面用的是TeX counts,或者可以用LaTeX counter,它們的區別:texdev.net/2009/11/17/tex-counts-and-latex-counters/
需把\newcounter\quoteCount改為\newcounter{quoteCount},把\iffodd\quoteCount改為\iffodd\value{quoteCount},把\advance\quoteCount by 1改為\stepcounter{quoteCount}:
- \documentclass{article}
- \newcounter{quoteCount}
- \let\rightquote='
- \catcode`'=13 % Make ' an active character
- \def'{%
- \ifodd\value{quoteCount}%
- \rightquote%
- \else
- `%
- \fi
- \stepcounter{quoteCount}%
- }
- \begin{document}
- Hello, 'world'!
- Hello, 'world'!
- \end{document}
复制代码 Why choice one or other method? Well, LaTeX does error checking and also adds some refinements (such as resetting one counter based on another). It also ensures you always include the appropriate \relax statements to avoid TeX picking up ‘extra’ material for numbers. On the other hand, if you want to do local assignments then you have to use TeX’s count registers: LaTeX always does global assignments. I tend to find that for document-level things counters are best (anything I actually want to print), whereas count registers are more flexible for programming. |
|