Showing posts with label LaTeX. Show all posts
Showing posts with label LaTeX. Show all posts

LaTeX tips: 章节样式

节是用 \@startsection{name}{level}{indent}{beforeskip}{afterskip}{style} 定义的.

indent 如果是正的,标题文本就会都有这样的 left-skip ;负的,则标题文本起始于外页边.

beforeskip 的绝对值为标题文本与上页的距离.正负号控制首段是否缩进.

afterskip 为标题文本也后续文本间距离,小于零时,可以得到接排的效果.

style 为标题文本的样式.可以在这里使用一些格式控制得到特殊的标题效果.

如: \hrule\medskip\raggedleft\itshape 或如: \centering\itshape

这是个例子:

\renewcommand{\subsection}{\@startsection
{subsection}{2}{0mm}{-\baselineskip}%
{.5\baselineskip}%
{\normalfont\normalsize\itshape}}

章和部是用 \secdef 定义的,定义形如:

\recommand{\part}{...\secdef\cmda\cmdb}
\newcommand{\cmda}[2][default]{...}
\newcommand{\cmdb}[1]{...}

LaTeX tips: 页面样式

在 Latex 里可以利用 fancyhdr 修改页面样式,也就是页眉,页脚.

这个宏包很方便.它将页眉,页脚分成左,中,右三部分, 还分为奇数页和偶数页两种情况.

其实对一些简单的情况,我们可以自己定义页面样式.

在 Latex 里, 是用 ps@page_style_name 的方式来调用,定义页面样式. 我们只要定义一个命令 ps@page_style_name, 在这个命令里设置好页眉,页脚即可. 这里举例:

\newcommand{\ps@mystyle}{%
  \renewcommand{\@oddhead}{Latex\hfil\textrm{\thepage}\hfil{}}%
  \renewcommand{\@evenhead}{{}\hfil\textrm{\thepage}\hfil Pagestyle}%
  \renewcommand{\@oddfoot}{}%
  \renewcommand{\@evenfoot}{}%
}

如果在页眉或页脚里含有章节信息,就要使用 mark 了. 在 TeXbook 里有一个很好的例子. 要用到 \lastmark \topmark \firstmark 之类的东西.

我们在 Latex 里只要利用 \leftmark \rightmark 即可. 这两个 mark 由 \chaptermark \sectionmark 之类的东西设置. 如果不满意可以自己将它改了.它带有一个章节标题的参数. 在重定义这些命令时你可能要用到 \markboth.

LaTeX package: GraphicxSP

GraphicxSP is an extension of the graphicx package. GraphicxSP embeds the graphic in the PDF document once, and allows the document author to use and re-use that same graphic without significantly increasing the file size. Additionally, GraphicxSP supports Adobe transparency imaging model.

LaTeX tips: 计数器重置

可以利用 \@addtoreset 将一个计数器加到另一个计算器, 使得第二个被增量及重置时第一个计数器会重置为 0. 但从计数器的重置列解除重置要麻烦一些:
\makeatletter
\def\rmreset#1#2{%
 \begingroup
 \def\@elt##1{%
   \expandafter\ifx\csname c@#1\expandafter\endcsname\csname c@##1\endcsname
   \else\noexpand\@elt{##1}\fi
 }
 \expandafter\xdef\csname cl@#2\endcsname{\csname cl@#2\endcsname}%
 \endgroup
}%
\makeatother
然后, 比如, 你可以这样用: \rmreset{subsection}{section}

LaTeX tips: \tracingmacros

如果想修改一些宏,但又不记起原来是怎么定义的时候,这就特别有用. 最好在你想修改的前面用 \tracingmacros=1, 而在后面用 \tracingmacros=0 以免输出太多.

LaTeX package: multido

提供 \multido, 方便实现循环. 使用语法 \multido{ variables }{ repetitions }{ stuff }
\begin{picture}(8,1)(0,-.5)
 \put(0,0){\vector(1,0){8}}
 \multido{\i=0+1,\n=0+0.25}{8}{%
   \put(\i,-.1){\line(0,1){.2}}
   \put(\i,-.2){\makebox(0,0)[t]{\n}}}
\end{picture}
\multido{}{10}{\TeX}
\multido{\d=2pt+3pt}{5}{\d, }
\multido{\n=2+3}{10}{\n, }
\multido{\i=2+-3}{10}{\i, }
\multido{\r=2+.305}{6}{\r, }
\multido{\n=2.00+-3.05}{8}{\n, }

LaTeX package: fancyhdr

方便的地定义页面样式, 尤其页眉页脚.
\fancyhead{} % clear all header fields
\fancyhead[RO,LE]{\bfseries The performance of new graduates}
\fancyfoot{} % clear all footer fields
\fancyfoot[LE,RO]{\thepage}
\fancyfoot[LO,CE]{From: K. Grant}
\fancyfoot[CO,RE]{To: Dean A. Smith}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}

LateX package: xspace

实现 \xspace 命令, 用以放在宏命令后面以在必要时提供空格而不是每次烦人的使用 \somemacros\ after text.

LaTeX package: delarray

在数组(array)上方便添加括号, 如
\begin{array}({cc})
a & b\\
c & d\\
\end{array}
\begin{equation}
f(x)=
\begin{array}\{{lr}.
0 & \text{if} x=0; \\
1 & \text{if} x>0; \\
-1& \text{if} x<0.>
尤其和 [t], [b] 等一起用更显有效.

LaTeX package: afterpage

此宏包定义了命令 \afterpage 可以在当前页面输出时执行一些命令. 在有浮动对象时, 可以用 \afterpage{\clearpage}, 比单用一个 \clearpage 好在可以不会引起页面过早输出. \afterpage{\clearpage\begin{figure}[H] . . . \end{figure}} 这将保证图例在下页面顶输出. \afterpage{\clearpage\input{ltfile}} \afterpage{\clearpage\input{ltfile}\clearpage}. ltfile 里是长表 longtable, 这样可以不致产生半页输出. 这个宏包比较 tricky, 需要理解一些 \output 的设计, 当时没看懂.

LaTeX Package: enumerate

这个宏包很小, 可以看看其实现. 提供环境 enumerate, 类似正常列表, 有可选参数表明项目号格式. 用 A, a, I, i, 1 分别表示 \Alph \alph \Roman \roman \arabic. 正常的字母 A, a, I, i, 1 需要放在 "{}" 里.
\begin{enumerate}[{A}-1]
\item test one
\item test two
\end{enumerate}
可以利用 \@enhook 来定义自己的项目号样式. 如文档里的例子:
\g@addto@macro\@enhook{%
\ifx *\@entemp
\def\@tempa{\@enLabel\fnsymbol}%
\fi}
这里 \g@addto@macro 已经定义, 全局地将内容添加到宏后面.

LaTeX online editor

http://www.texify.com/links.php 可以直接联结图片, 如 http://texify.com/img/$\int\frac{1}{1+x^2}=\arctan(x)$.gif

http://www.codecogs.com/components/equationeditor/equationeditor.php 有符号编辑器, 可以联结图片, 如 http://www.codecogs.com/eq.latex?x^n+y^n=z^n

http://www.bgoncalves.com/online/latex/ 有符号编辑器, 不清楚是否可以联结图片, 至少不是很方便.

定义代码与效果并存的环境

例如, 需要一个环境 Foo, 使得

\begin{Foo}
some source code
\end{Foo}

得到:

===========
some source code
===========
code result(image)
===========

关键是 verbatim 的问题

我曾经在 CTeX 上发贴求助, 最后还是在别人提示下找到方法.

ctex-faq.sty 里将代码写到一个文件里, 再 input 进来实现的.

仔细看了 eTeX 文档, 发现 \scantokens 可以不用文件操作得到类似的效果.

代码片段:

\newenvironment*{AsyExample}[1][type=SR]{%
\stepcounter{asy}%
\setkeys[pt]{AsyExample}{#1}%
\edef\AsyExampleSize{\AsyExampleSize}
\begingroup
\@bsphack
\let\do\@makeother\dospecials\catcode`\^^M\active
\AsyExample@toks={}
\def\verbatim@processline{% \expandafter\addto@hook\expandafter\AsyExample@toks\expandafter{\the\verbatim@line^^J}
}%
\verbatim@start}{%
\@esphack
\global\AsyExample@toks\AsyExample@toks
\endgroup
\AsyExample@Source
\AsyExample@Result
}

然后在 \AsyExample@Source 等里显示或扫描 \AsyExample@toks 即可.

LaTeX Source2e

ltsect.dtx

\title, \author, \date, \thanks, \and, \maketitle, \title

\@secpenalty 节分页惩罚值.

\@startsection \@startsection{ name }{ level }{ indent }{ beforeskip }{ afterskip }{ style }*[ altheading ]{ heading }

name 节名, 例如 subsection.

level 节深, 例如, chapter=1, section=2.

indent 左缩进.

beforeskip 绝对值为节头上距, 如果为负, 节后段落缩进被禁.

afterskip 正值为节头下距, 负值为节右距.

style节头样式, 例 \bfseries\MakeUppercase.

\@seccntformat 格式化节号.

\if@afterindent 节后段落是否缩进, 可以通过 \let\@afterindentfalse\@afterindenttrue 来使首段落缩进, 更符合中文习惯.

\@afterheading 定制节头钩子.

\@hangfrom 竖直模式, 挂起缩进.

\c@secnumdepth, \c@tocdepth 节目深度和目录深度.

\secdef \secdef{\STARCMD}{\UNSTARCMD}

\sectionmark, \subsectionmark, \subsubsectionmark, \paragraphmark, \subparagraphmark 页面样式用, 如页眉, 页脚.

\@starttoc 打开辅助文件.

\addcontentsline \addcontentsline{ table }{ type }{ entry } 向 jobname.table 中添加.

\addtocontents \addtocontents{ table }{ text } .

\contentsline \contentsline{ type }{ entry }{ page }

\@dottedtocline \@dottedtocline{ level }{ indent }{ numwidth }{ title }{ page }

\numberline\contentsline 中使用, 将数字左对齐放在宽为 \@tempdima 的盒子里.

ltfloat.dtx

ltidxglo.dtx

ltbibl.dtx

ltpage.dtx

\pagestyle \pagestyle{ style }, 利用 \ps@stylename 设置相应页面.

\@oddhead, \@oddfoot, \@evenhead, \@evenfoot 在页面样式里定义.

\thispagestyle 当前页面样式.

\raggedbottom

\flushbottom

\sloppy

\sloppypar

\fussy

\overfullrule

ltoutput.dtx

页面布局参数 : \topmargin \oddsidemargin \evensidemargin \headheight \headsep \footskip \textheight \textwidth \columnsep \columnseprule \columnwidth

\@textbottom, \@texttop 执行于页面盒子的底部和顶部的宏.

页面样式参数: \floatsep \textfloatsep \topfigrule \botfigrule \intextsep \dblfloatsep \dbltextfloatsep \dblfigrule \@fptop \@fpsep \@fpbot \@dblfptop, \@dblfpsep, \@dblfpbot

\@oddhead, \@evenhead, \@oddfoot, \@evenfoot 页眉页脚的宏.

\@specialstyle 特殊样式?

....

ltclass.dtx

lthyphen.dtx

ltfinal.dtx

LaTeX Source2e

ltlogos.dtx

\TeX, \LaTeX, \LaTeXe

ltfiles.dtx

\IfFileExists, \InputIfFileExists

ltoutenc.dtx

.... ... .. .

ltcounts.dtx

\newcounter \setcounter \addtocounter \stepcounter \refstepcounter \value \arabic \roman \Roman \alph \Alph \fnsymbol

\@addtoreset

ltlength.dtx

\newlength \setlength \addtolength \settowidth \settoheight \settodepth \newlength \setlength \addtolength \settoheight \settodepth \settowidth

ltfssbas.dtx

.... ... .. .

ltfsstrc.dtx

.... ... .. .

ltfsscmp.dtx

.... ... .. .

ltfssdcl.dtx

ltfssini.dtx

fontdef.dtx

preload.dtx

ltfntcmd.dtx

ltpageno.dtx

\pagenumbering

ltxref.dtx

ltmiscen.dtx

ltmath.dtx

ltlists.dtx

ltboxes.dtx

lttab.dtx

ltpictur.dtx

ltthm.dtx

LaTeX Source2e

ltspace.dtx

\pagebreak, \nopagebreak 四个级别建议是否页面分页.

\linebreak, \nolinebreak 四个级别建议是否换行.

\samepage 前后在同一页.

\newline 换行.

\addvspace \addpenalty \vspace

\smallskip, \medskip, \bigskip, \smallskipamount, \medskipamount, \bigskipamount

\nobreakdashes \nobreakspace

\hspace,

\fill \fill = 0pt plus 1fill

\stretch 拉伸度.

\thinspace, \negthinspace, \enspace

\enskip, \quad, \qquad

\obeycr, \restorecr

LaTeX Source2e

ltspace.dtx

\pagebreak, \nopagebreak 四个级别建议是否页面分页.

\linebreak, \nolinebreak 四个级别建议是否换行.

\samepage 前后在同一页.

\newline 换行.

\addvspace \addpenalty \vspace

\smallskip, \medskip, \bigskip, \smallskipamount, \medskipamount, \bigskipamount

\nobreakdashes \nobreakspace

\hspace,

\fill \fill = 0pt plus 1fill

\stretch 拉伸度.

\thinspace, \negthinspace, \enspace

\enskip, \quad, \qquad

\obeycr, \restorecr

LaTeX Source2e

ltpar.dtx

\@setpar 长期的改变 \par, \@par.

\@restorepar 恢复 \par\@par.

LaTeX Source2e

lterror.dtx

\MessageBreak 打印换行符及 \@msg@continuation, 外部为 \relax, 但在内部被定义为 \@message@break.

\GenericInfo 接受两个参数, 一为连续体, 一为消息体.

\GenericWarning 打印在屏幕上的警告.

\GenericError 四个参数, 连续体, 错误消息, 进一步消息, 帮助消息.

\PackageError, \PackageWarning, \PackageWarningNoLine, \PackageInfo, \ClassError, \ClassWarning, \ClassWarningNoLine, \ClassInfo

\PackageError{ package }{ error }{ help } \PackageWarning{ package }{ warning } \PackageWarningNoLine{ package }{ warning } \PackageInfo{ package }{ info }

\@latex@error, \@latex@warning, \@latex@warning@no@line, \@latex@info, \@latex@info@no@line LATEX 内部消息.

\@spaces 四个空格.

\@eha, \@ehb, \@ehc, \@ehd 更一般的错误消息.

...

LaTeX Source2e

ltcntrl.dtx

\@whilenum 数字条件循环, \@whilenum TEST \do BODY. \@iwhilenum\@whilenum 内部使用.

\@whiledim, \@iwhiledim 长度条件循环.

\@whilesw \@whilesw SWITCH \fi {BODY}. \@iwhilesw\@whilesw 内部使用.

\@nnil \def\@nnil{\@nil}

\@empty 空宏.

\@fornoop for 循环辅助宏, 空操作.

\@for \@for NAME := LIST \do {BODY}.

\@forloop \@for 内部使用.

@tfor \@tfor NAME := LIST \do {BODY}

\@removeelement \@removeelement{ element }{ list }{ cs } 从逗号分隔的列 表中删去一个元素并将其定义到指定宏.

\def\@removeelement#1#2#3{%
 \def\reserved@a##1,#1,##2\reserved@a{##1,##2\reserved@b}%
 \def\reserved@b##1,\reserved@b##2\reserved@b{%
   \ifx,##1\@empty\else##1\fi}%
 \edef#3{%
   \expandafter\reserved@b\reserved@a,#2,\reserved@b,#1,\reserved@a}}