Debian Codegraph @

texmf-dist/doc/latex/ctex-faq/src/ctex-faq.sty

raw
1 %% This is a LaTeX2e package for the CTeX FAQ document.
2 %%
3 %% Created by aloft ([email protected])
4 %%
5 %% Version 0.8 (24-May-2009)
6 %%
7 %% $Id: ctex-faq.sty 83 2007-01-30 09:48:43Z aloft $
8 %%
9 \def\filedate{2009/05/24}
10 \def\fileversion{0.8}
11 \NeedsTeXFormat{LaTeX2e}[1994/06/01]
12 \ProvidesPackage{ctex-faq}[\filedate\space\fileversion\space(Chinese TeX FAQ macros)]
13 %
14 %
15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16 %
17 % Options
18 %
19 \newif\ifnewfaqmark
20 \newfaqmarktrue
21 %
22 %
23 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24 %
25 % Loading packages
26 %
27 %
28 \RequirePackage{ifpdf}
29 \RequirePackage[UTF8,fancyhdr]{ctex}
30 \ifpdf
31 \RequirePackage[pdftex,%
32 unicode,%
33 bookmarksnumbered,%
34 colorlinks,%
35 linkcolor=blue,%
36 hyperindex,%
37 plainpages=false,%
38 pdfstartview=FitH]{hyperref}
39 \else
40 \RequirePackage[dvipdfm,%
41 unicode,%
42 bookmarksnumbered,%
43 colorlinks,%
44 linkcolor=blue,%
45 hyperindex,%
46 plainpages=false,%
47 pdfstartview=FitH]{hyperref}
48 \fi
49 %
50 %
51 \RequirePackage{color,verbatim,cite}
52 \RequirePackage{texnames,makeidx,indentfirst}
53 \RequirePackage{amsmath,amssymb,amsfonts,bm,manfnt}
54 \RequirePackage{textcomp}
55 %
56 %
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 %
59 % Typesetting TeX names
60 %
61 %
62 \DeclareRobustCommand\CTeX{$\mathbb{C}$\kern-.05em\TeX}
63 \DeclareRobustCommand\MiKTeX{MiK\TeX}
64 \DeclareRobustCommand\fpTeX{fp\TeX}
65 \DeclareRobustCommand\teTeX{te\TeX}
66 \DeclareRobustCommand\ConTeXt{Con\TeX{}t}
67 \DeclareRobustCommand\TeXLive{\TeX{}Live}
68 %
69 \newcommand\PS{PostScript}
70 %
71 %
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 %
74 % Modifing Styles
75 %
76 %
77 \setlength{\parskip}{0.75ex plus .2ex minus .5ex}
78 \renewcommand{\baselinestretch}{1.2}
79 %
80 % we don't want headings
81 \pagestyle{plain}
82 %
83 % we `number' our sections alphabetically
84 \renewcommand{\thesection}{\Alph{section}}
85 %
86 % we use superscript numerical citation with brackets
87 \def\@cite#1{\textsuperscript{[#1]}}
88 %
89 %
90 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91 %
92 % Redefine some commands and environments
93 %
94 %
95 \newcommand*\contrib[2][]{{\it #2}\hspace*{1ex}%
96 \def\reserved@a{#1}%
97 \ifx\reserved@a\@empty
98 (no email)
99 \else
100 (\href{mailto:#1}{#1})
101 \fi}
102 %
103 % Quoted URL
104 \newcommand\faqurl[1]{\begin{quote}\url{#1}\end{quote}}
105 %
106 % Make index entry
107 \newcommand\faqindex[1]{\index{#1}#1}
108 %
109 % Quoted verbatim environment
110 \@namedef{prompt}{\quote\verbatim}
111 \expandafter\def\csname endprompt\endcsname {\endverbatim\endquote}
112 %
113 %
114 \newenvironment{lined}[1]%
115 {\begin{center}\begin{minipage}{#1}\hrule\medskip}
116 {\vspace{-1ex}\hrule \end{minipage}\end{center}}
117 %
118 % Marginal notes
119 \newcommand{\MarginalNotes}[1]{%
120 \hskip 1sp \marginpar{\small\sffamily\raggedright #1}}
121 %
122 % Set RCS Keywords
123 \def\RCS{\RCS@process}
124 \def\RCS@process$#1: #2 ${%
125 \def\RCS@keyword{#1}%
126 \def\RCS@value{#2}%
127 \ifx\RCS@value\empty%
128 \def\RCS@value{N/A}%
129 \fi%
130 \@ifundefined{RCS@handle\RCS@keyword}%
131 {\expandafter\edef\csname RCS\RCS@keyword\endcsname{\RCS@value}}%
132 {\csname RCS@handle\RCS@keyword\endcsname}}
133 \def\RCS@handleDate{%
134 \ifx\RCS@value{N/A}%
135 \def\RCSDate\today%
136 \let\RCSTime\relax%
137 \else%
138 \expandafter\RCS@setDate\RCS@value\@nil%
139 \fi}
140 \def\RCS@setDate#1-#2-#3 #4\@nil{%
141 \def\RCSday{#3}%
142 \def\RCSmonth{#2}%
143 \def\RCSyear{#1}%
144 \def\RCSDate{\begingroup%
145 \day \number\RCSday%
146 \month \number\RCSmonth%
147 \year \number\RCSyear%
148 \today\endgroup}
149 \def\RCSTime{#4}}
150 %
151 %
152 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153 %
154 % Typesetting Commands
155 %
156 %
157 \newenvironment{latexcmd}%
158 {\list{}{}\item\relax%
159 \begin{tabular}{|l|}\hline\rule{0pt}{1em}\ignorespaces\small}%
160 {\\\hline\end{tabular}\endlist}
161 %
162 %
163 % Index entry for an command
164 \newcommand\bs{\texorpdfstring{\texttt{\symbol{92}}}{\textbackslash}} %Print backslash
165 \def\cmdname{Commands}
166 \newcommand\cmdindex[1]{%
167 \index{\cmdname!#1@\texttt{\bs#1}}%
168 \index{#1@\texttt{\hspace*{-1.2ex}\bs #1}}}
169 \newcommand\cmd[1]{\cmdindex{#1}\texttt{\bs#1}} %Print command
170 \newcommand\cs[1]{\texttt{\bs#1}} %Print command without index
171 %
172 % Index entry for an package
173 \def\pkgname{Packages}
174 \newcommand\pkgindex[1]{%
175 \index{\pkgname!#1@\textsf{#1}}%
176 \index{#1@\textsf{#1}}}
177 \newcommand\pkg[1]{\pkgindex{#1}\textsf{#1}} %Print package
178 %
179 % Index entry for an environment
180 \def\envname{Environments}
181 \newcommand\envindex[1]{%
182 \index{\envname!#1@\texttt{#1}}%
183 \index{#1@\texttt{#1}}}
184 \newcommand\env[1]{\envindex{#1}\texttt{#1}}
185 %
186 % Argument and optional argument
187 \def\parg#1{\mbox{$\langle${\it #1\/}$\rangle$}}
188 \def\@smarg#1{{\tt\string{}\parg{#1}{\tt\string}}}
189 \def\@marg#1{{\tt\string{}{\rm #1}{\tt\string}}}
190 \def\marg{\@ifstar\@smarg\@marg}
191 \def\@soarg#1{{\tt[}\parg{#1}{\tt]}}
192 \def\@oarg#1{{\tt[}{\rm #1}{\tt]}}
193 \def\oarg{\@ifstar\@soarg\@oarg}
194 %
195 %
196 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
197 %
198 % Typesetting Code Fragments
199 %
200 %
201 %% using listings.sty
202 %%\lstset{language=[LaTeX]TeX}
203 %%\lstset{framexleftmargin=5pt, frame=shadowbox, rulesepcolor=\color{blue}}
204 %%\lstset{xleftmargin=20pt, xrightmargin=20pt}
205 %%\lstset{breaklines=false}
206 %%\lstnewenvironment{code}[2][]
207 %% {\lst@TestEOLChar{#2}%
208 %% \lstset{#1}%
209 %% \csname\@lst @SetFirstNumber\endcsname}
210 %% {\csname\@lst @SaveFirstNumber\endcsname}
211 %%
212 %% using verbatim.sty
213 %%\@namedef{code}{\quote\begingroup\@verbatim\frenchspacing\@vobeyspaces\verbatim@start}
214 %%\expandafter\def\csname endcode\endcsname {\endverbatim\endquote}
215 %
216 %
217 % This part is hacked from the verbatim.sty and lshort.sty
218 %
219 \definecolor{example@bkcolor}{gray}{.875}
220 %
221 \newwrite\example@out
222 \def\example@start{%
223 \begingroup% Lets Keep the Changes Local
224 \@bsphack
225 \immediate\openout \example@out \jobname.exa
226 \let\do\@makeother\dospecials\catcode`\^^M\active
227 \def\verbatim@processline{%
228 \immediate\write\example@out{\the\verbatim@line}}%
229 \verbatim@start}
230 \def\example@finish{\immediate\closeout\example@out\@esphack\endgroup}
231 \def\example@code#1#2{%
232 \colorbox{#1}{%
233 \begin{minipage}[c]{#2}%
234 \small\verbatiminput{\jobname.exa}%
235 \end{minipage}%
236 }%
237 }
238 \def\example@output#1{%
239 \let\savefboxrule\fboxrule%
240 \let\savefboxsep\fboxsep%
241 \setlength{\fboxrule}{0.1pt}%
242 \setlength{\fboxsep}{3mm}%
243 \fbox{%
244 \begin{minipage}[c]{#1}%
245 \setlength{\fboxrule}{\savefboxrule}%
246 \setlength{\fboxsep}{\savefboxsep}%
247 \setlength{\parskip}{1ex plus 0.4ex minus 0.2ex}%
248 \begin{trivlist}\item\small\input{\jobname.exa}\end{trivlist}
249 \end{minipage}
250 }%
251 }
252 %
253 % This is two environments to set LaTeX examples.
254 %
255 % example: On the left side the source text and on the
256 % right side the typeset text.
257 %
258 \newenvironment{example}%
259 {\example@start}%
260 {\example@finish%
261 \list{}{\itemindent-\leftmargin}\item\relax%
262 \makebox[\textwidth][c]{%
263 \example@code{example@bkcolor}{0.5\textwidth}%
264 \hspace{10pt}%
265 \example@output{0.4\textwidth}%
266 }%
267 \endlist}
268 %
269 % code: Only the source text
270 %
271 \newenvironment{code}%
272 {\example@start}%
273 {\example@finish%
274 \list{}{\itemindent-\leftmargin}\item\relax%
275 \makebox[\textwidth][c]{%
276 \example@code{example@bkcolor}{0.96\textwidth}%
277 }%
278 \endlist}
279 %
280 %
281 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
282 %
283 % Dangerous and doubly dangerous bends
284 %
285 %
286 \newlength{\dbend@width}
287 \newlength{\ddbend@width}
288 \newlength{\dbend@voffset}
289 \def\setdbend@width{%
290 \settowidth{\dbend@width}{\dbend}%
291 \setlength{\ddbend@width}{\dbend@width}%
292 \multiply\dbend@width by 2%
293 \multiply\ddbend@width by 3%
294 \advance\ddbend@width by 1pt%
295 \settoheight{\dbend@voffset}{\dbend}%
296 \multiply\dbend@voffset by 22%
297 \divide\dbend@voffset by 15%
298 \advance\dbend@voffset by -\baselineskip}
299 %
300 % This parts is hacked from TeXbook
301 %
302 \def\d@nger{\begingroup\clubpenalty=10000\def\par{\endgraf\endgroup}
303 \setdbend@width\noindent\hangindent\dbend@width\hangafter=-2
304 \lower-\dbend@voffset\hbox to0pt{\hskip-\hangindent\dbend\hfill}}
305 %
306 \def\dd@nger{\begingroup\clubpenalty=10000\def\par{\endgraf\endgroup}
307 \setdbend@width\noindent\hangindent\ddbend@width\hangafter=-2
308 \lower-\dbend@voffset\hbox to0pt{\hskip-\hangindent\dbend\kern1pt\dbend\hfill}}
309 %
310 \def\danger{\d@nger}
311 \def\ddanger{\dd@nger}
312 \def\enddanger{\endgraf\endgroup}
313 %
314 %
315 \newenvironment{advanced}{\CJKfamily{kai}}{\CJKfamily{com}}
316 %
317 %
318 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
319 %
320 % Typesetting Questions
321 %
322 %
323 \setcounter{tocdepth}{3}
324 \setcounter{secnumdepth}{3}
325 \renewcommand\appendix{\par\setcounter{secnumdepth}{-1}}
326 %
327 % tableofcontents definition from article.cls
328 \renewcommand\tableofcontents{%
329 \pdfbookmark[1]{\contentsname}{contents}%
330 \section*{\contentsname
331 \@mkboth{%
332 \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
333 \@starttoc{toc}%
334 }
335 %
336 % thebibliography definition from article.cls
337 \renewenvironment{thebibliography}[1]
338 {\section{\refname}%
339 \@mkboth{\MakeUppercase\refname}{\MakeUppercase\refname}%
340 \list{\@biblabel{\@arabic\c@enumiv}}%
341 {\settowidth\labelwidth{\@biblabel{#1}}%
342 \leftmargin\labelwidth
343 \advance\leftmargin\labelsep
344 \@openbib@code
345 \usecounter{enumiv}%
346 \let\p@enumiv\@empty
347 \renewcommand\theenumiv{\@arabic\c@enumiv}}%
348 \sloppy
349 \clubpenalty4000
350 \@clubpenalty \clubpenalty
351 \widowpenalty4000%
352 \sfcode`\.\@m}
353 {\def\@noitemerr
354 {\@latex@warning{Empty `thebibliography' environment}}%
355 \endlist}
356 %
357 % theindex definition from article.cls
358 \renewenvironment{theindex}
359 {\if@twocolumn
360 \@restonecolfalse
361 \else
362 \@restonecoltrue
363 \fi
364 \columnseprule \z@
365 \columnsep 35\p@
366 \twocolumn[\section{\indexname}]%
367 \@mkboth{\MakeUppercase\indexname}%
368 {\MakeUppercase\indexname}%
369 \thispagestyle{plain}\parindent\z@
370 \parskip\z@ \@plus .3\p@\relax
371 \let\item\@idxitem}
372 {\if@restonecol\onecolumn\else\clearpage\fi}
373 %
374 % section definition from article.cls
375 \renewcommand\section{\@startsection {section}{\@ne}{\z@}%
376 {-3.5ex \@plus -1ex \@minus -.2ex}%
377 {2.3ex \@plus .2ex}%
378 {\normalfont\Large\bfseries}}
379 \renewcommand*\l@section[2]{%
380 \ifnum \c@tocdepth >\z@
381 \addpenalty\@secpenalty
382 \addvspace{1.0em \@plus\p@}%
383 \setlength\@tempdima{1.5em}%
384 \begingroup
385 \parindent \z@ \rightskip \@pnumwidth
386 \parfillskip -\@pnumwidth
387 \leavevmode \bfseries
388 \advance\leftskip\@tempdima
389 \hskip -\leftskip
390 #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
391 \endgroup
392 \fi}
393 %
394 % This parts is hacked from faq.sty of UKTUG
395 %
396 % subsections: these are a curious half-breed between latex sections
397 % and subsections -- as designed, i'm not intending there ever to be
398 % more than 9 per section (hahaha)
399 \renewcommand\subsection{\@startsection{subsection}{\tw@}{\z@}%
400 {-3.25ex\@plus -1ex \@minus -.2ex}%
401 {1.5ex \@plus .2ex}%
402 {\normalfont\large\bfseries}}
403 \renewcommand*\l@subsection[2]{%
404 \ifnum \c@tocdepth >\@ne
405 \addpenalty\@secpenalty
406 \addvspace{0.5em \@plus\p@}%
407 \setlength\@tempdima{2.3em}%
408 \begingroup
409 \parindent \z@ \rightskip \@pnumwidth
410 \parfillskip -\@pnumwidth
411 \leavevmode \bfseries
412 \advance\leftskip\@tempdima
413 \hskip -\leftskip
414 #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
415 \endgroup
416 \fi}
417 %
418 %
419 % the question structure
420 %
421 \ifx\faqlastver\undefined
422 \let\faqlastver\faqversion
423 \fi
424 %
425 %
426 \newcommand\listofnewfaqs{\@starttoc{lon}}
427 \newcommand\listofrevfaqs{\@starttoc{lor}}
428 \newcommand\tableofnewfaqs{\@starttoc{ton}}
429 \newcommand\tableofrevfaqs{\@starttoc{tor}}
430 %
431 %
432
433 \newcommand{\FAQChangeList}{\clearpage%
434 \ifx\faqlastver\faqversion
435 \section{ChangeList of v\faqversion}
436 \else
437 \section{ChangeList of v\faqlastver\ --\ v\faqversion}
438 \fi
439 \subsection*{New}\begin{small}\tableofnewfaqs\end{small}
440 \subsection*{Revised}\begin{small}\tableofrevfaqs\end{small}
441 \vspace{\stretch{1}}
442 \ifx\RCSDate\undefined\else
443 \noindent\begin{small}(Last updated: \CTEXoptions[today=small]\RCSDate)\end{small}
444 \fi}
445 %
446 %
447 \newif\ifquestion@new
448 \question@newfalse
449 \def\question@ver#1.#2|#3.#4\@nil{%
450 \question@newtrue
451 \ifnum#3<#1 \question@newfalse
452 \else \ifnum#3=#1 \ifnum#4<#2 \question@newfalse \fi \fi
453 \fi}
454 \def\question@chk#1#2#3#4#5#6{%
455 \expandafter\question@ver\faqlastver|#6\@nil%
456 \ifquestion@new
457 \addtocontents{#1}{\protect\ref{#4}}
458 \addcontentsline{#2}{question}{\protect\numberline{\thequestion}#5}
459 \ifnewfaqmark
460 \marginpar{\vspace{-1em}\small\sffamily\raggedright{\color{red}#3}\\v#6}
461 \fi
462 \fi}
463 %
464 %
465 % Question[label name]{question asked}{imported version}{revised version}
466 % if [label name] present, the named label is assigned with Qlabel
467 \newcounter{question}
468 \newcommand\Question[4][]{%
469 \qu@stion{#2}%
470 \def\reserved@a{#1}%
471 \ifx\reserved@a\@empty
472 \PackageWarning{ctex-faq}{Question "#2" has no label}%
473 \def\reserved@a{Q-\thequestion}
474 \fi
475 \Qlabel{\reserved@a}%
476 \question@chk{lon}{ton}{New}{\reserved@a}{#2}{#3}
477 \ifquestion@new\else
478 \question@chk{lor}{tor}{Revised}{\reserved@a}{#2}{#4}
479 \fi
480 }
481 \newcommand\qu@stion{\@startsection{question}{\thr@@}{\z@}%
482 {-3.25ex \@plus -1ex \@minus -.2ex}%
483 {0.75ex \@plus .2ex}%
484 {\normalfont\normalsize\bfseries}%
485 }
486 \newcommand*\questionmark[1]{}
487 \newcommand*\l@question{\@dottedtocline{2}{2.0em}{2.3em}}
488 \newcommand*\toclevel@question{2}
489 %
490 %
491 % Qlabel and Qref: define and refer to labels
492 \def\Qname{Question}
493 % hyperref version of label doesn't get set until begin document
494 \AtBeginDocument{\let\Qlabel\label}
495 \newcommand\Qref[2][\Qname]{{#1}~\ref{#2}}
496 %
497 %
498 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
499 %
500 %
501 \endinput
502 %%
503 %% End of file `ctex-faq.sty'.