■構成要素 \@startsectionマクロは6個の必須引数と,オプションとして*と1個の オプション引数と1個の必須引数をとります。
\@startsection{名}{レベル}{字下げ}{前アキ}{後アキ}{スタイル}
*[別見出し]{見出し}
それぞれの引数の意味は次の通りです。
名 ユーザレベルコマンドの名前です(例: section)。
レベル 見 出 し の 深 さ を 示 す 数 値 で す (chapter=1, section=2, …)。 こ の 数 値 が secnumdepth 以下のとき見出し番号を出力します。
字下げ 見出しの字下げ量です。
前アキ この値の絶対値が見出し上側の空きです。負の場合は,見出し直後の段落をインデ ントしません。
後アキ 正の場合は,見出しの下の空きです。負の場合は,絶対値が見出しの右の空きです
(見出しと同じ行から本文を始めます)。 スタイル 見出しの文字スタイルの設定です。
* この*印がないと,見出し番号を付け,見出し番号のカウンタに1を加算します。
別見出し 目次や柱に出力する見出しです。
見出し 見出しです。
見出しの命令は通常\@startsectionとその最初の6個の引数として定義されます。
次 は \@startsection の 定 義 で す。 情 報 処 理 学 会 論 文 誌 ス タ イ ル フ ァ イ ル
(ipsjcommon.sty)を参考にさせていただきましたが,完全に行送りが \baselineskip の整数倍にならなくてもいいから前の行と重ならないようにしました。
1410\def\@startsection#1#2#3#4#5#6{%
1411 \if@noskipsec \leavevmode \fi
1412 \par
1413% 見出し上の空きを \@tempskipa にセットする 1414 \@tempskipa #4\relax
1415% \@afterindent は見出し直後の段落を字下げするかどうかを表すスイッチ 1416 \if@english \@afterindentfalse \else \@afterindenttrue \fi
1417% 見出し上の空きが負なら見出し直後の段落を字下げしない 1418 \ifdim \@tempskipa <\z@
1419 \@tempskipa -\@tempskipa \@afterindentfalse
1420 \fi
1421 \if@nobreak
1422% \everypar{\everyparhook}% これは間違い
1423 \everypar{}%
1424 \else
1425 \addpenalty\@secpenalty
1426% 次の行は削除
1427% \addvspace\@tempskipa
1428% 次の \noindent まで追加 1429 \ifdim \@tempskipa >\z@
1430 \if@slide\else
1431 \null
1432 \vspace*{-\baselineskip}%
1433 \fi
1434 \vskip\@tempskipa
1435 \fi
1436 \fi
1437 \noindent
1438% 追加終わり
1439 \@ifstar
1440 {\@ssect{#3}{#4}{#5}{#6}}%
1441 {\@dblarg{\@sect{#1}{#2}{#3}{#4}{#5}{#6}}}}
\@sectと\@xsectは,前のアキがちょうどゼロの場合にもうまくいくように,多少変え てあります。\everyparhookも挿入しています。
1442\def\@sect#1#2#3#4#5#6[#7]#8{%
1443 \ifnum #2>\c@secnumdepth
1444 \let\@svsec\@empty
1445 \else
1446 \refstepcounter{#1}%
1447 \protected@edef\@svsec{\@seccntformat{#1}\relax}%
1448 \fi
1449% 見出し後の空きを \@tempskipa にセット 1450 \@tempskipa #5\relax
1451% 条件判断の順序を入れ換えました 1452 \ifdim \@tempskipa<\z@
1453 \def\@svsechd{%
1454 #6{\hskip #3\relax
1455 \@svsec #8}%
1456 \csname #1mark\endcsname{#7}%
1457 \addcontentsline{toc}{#1}{%
1458 \ifnum #2>\c@secnumdepth \else
1459 \protect\numberline{\csname the#1\endcsname}%
1460 \fi
1461 #7}}% 目次にフルネームを載せるなら #8
1462 \else
1463 \begingroup
1464 \interlinepenalty \@M % 下から移動
1465 #6{%
1466 \@hangfrom{\hskip #3\relax\@svsec}%
1467% \interlinepenalty \@M % 上に移動
1468 #8\@@par}%
1469 \endgroup
1470 \csname #1mark\endcsname{#7}%
1471 \addcontentsline{toc}{#1}{%
1472 \ifnum #2>\c@secnumdepth \else
1473 \protect\numberline{\csname the#1\endcsname}%
1474 \fi
1475 #7}% 目次にフルネームを載せるならここは #8
1476 \fi
1477 \@xsect{#5}}
二つ挿入した \everyparhookのうち後者が \paragraph 類の後で2回実行され,それ 以降は前者が実行されます。
1478\def\@xsect#1{%
1479% 見出しの後ろの空きを \@tempskipa にセット
1480 \@tempskipa #1\relax
1481% 条件判断の順序を変えました 1482 \ifdim \@tempskipa<\z@
1483 \@nobreakfalse
1484 \global\@noskipsectrue
1485 \everypar{%
1486 \if@noskipsec
1487 \global\@noskipsecfalse
1488 {\setbox\z@\lastbox}%
1489 \clubpenalty\@M
1490 \begingroup \@svsechd \endgroup
1491 \unskip
1492 \@tempskipa #1\relax
1493 \hskip -\@tempskipa
1494 \bxjs@ltj@inhibitglue
1495 \else
1496 \clubpenalty \@clubpenalty
1497 \everypar{\everyparhook}%
1498 \fi\everyparhook}%
1499 \else
1500 \par \nobreak
1501 \vskip \@tempskipa
1502 \@afterheading
1503 \fi
1504 \if@slide
1505 {\vskip-6\p@?\maybeblue\hrule height0\p@? depth1\p@?\vskip7\p@?\relax}%
1506 \fi
1507 \par % 2000-12-18
1508 \ignorespaces}
1509\def\@ssect#1#2#3#4#5{%
1510 \@tempskipa #3\relax
1511 \ifdim \@tempskipa<\z@
1512 \def\@svsechd{#4{\hskip #1\relax #5}}%
1513 \else
1514 \begingroup
1515 #4{%
1516 \@hangfrom{\hskip #1}%
1517 \interlinepenalty \@M #5\@@par}%
1518 \endgroup
1519 \fi
1520 \@xsect{#3}}
上記の定義中の\bxjs@ltj@inhibitglueはLuaTEX-jaで用いられるフック。
1521\let\bxjs@ltj@inhibitglue\@empty
■柱関係の命令
\chaptermark
\sectionmark
\subsectionmark
\subsubsectionmark
\paragraphmark
\subparagraphmark
\...markの形の命令を初期化します(第6節参照)。\chaptermark 以外はLATEX本体で 定義済みです。
1522\newcommand*\chaptermark[1]{}
1523% \newcommand*{\sectionmark}[1]{}
1524% \newcommand*{\subsectionmark}[1]{}
1525% \newcommand*{\subsubsectionmark}[1]{}
1526% \newcommand*{\paragraphmark}[1]{}
1527% \newcommand*{\subparagraphmark}[1]{}
■カウンタの定義
\c@secnumdepth secnumdepthは第何レベルの見出しまで番号を付けるかを決めるカウンタです。
1528%<!book&!report>\setcounter{secnumdepth}{3}
1529%<book|report>\setcounter{secnumdepth}{2}
\c@chapter
\c@section
\c@subsection
\c@subsubsection
\c@paragraph
見出し番号のカウンタです。\newcounter の第1引数が新たに作るカウンタです。これは 第2引数が増加するたびに0に戻されます。第2引数は定義済みのカウンタです。
1530\newcounter{part}
56
1531%<book|report>\newcounter{chapter}
1532%<book|report>\newcounter{section}[chapter]
1533%<!book&!report>\newcounter{section}
1534\newcounter{subsection}[section]
1535\newcounter{subsubsection}[subsection]
1536\newcounter{paragraph}[subsubsection]
1537\newcounter{subparagraph}[paragraph]
\thepart
\thechapter
\thesection
\thesubsection
\thesubsubsection
\theparagraph
\thesubparagraph
カウンタの値を出力する命令\the何々を定義します。
カウンタを出力するコマンドには次のものがあります。
\arabic{COUNTER} 1, 2, 3, …
\roman{COUNTER} i, ii, iii, …
\Roman{COUNTER} I, II, III, …
\alph{COUNTER} a, b, c, …
\Alph{COUNTER} A, B, C, …
\kansuji{COUNTER} 一,二,三, …
以下ではスペース節約のため@の付いた内部表現を多用しています。
1538\renewcommand{\thepart}{\@Roman\c@part}
1539%<!book&!report>% \renewcommand{\thesection}{\@arabic\c@section}
1540%<!book&!report>\renewcommand{\thesection}{\presectionname\@arabic\c@section\postsectionname}
1541%<!book&!report>\renewcommand{\thesubsection}{\@arabic\c@section.\@arabic\c@subsection}
1542%<*book|report>
1543\renewcommand{\thechapter}{\@arabic\c@chapter}
1544\renewcommand{\thesection}{\thechapter.\@arabic\c@section}
1545\renewcommand{\thesubsection}{\thesection.\@arabic\c@subsection}
1546%</book|report>
1547\renewcommand{\thesubsubsection}{%
1548 \thesubsection.\@arabic\c@subsubsection}
1549\renewcommand{\theparagraph}{%
1550 \thesubsubsection.\@arabic\c@paragraph}
1551\renewcommand{\thesubparagraph}{%
1552 \theparagraph.\@arabic\c@subparagraph}
\@chapapp
\@chappos
\@chapappの初期値は \prechaptername(第)です。
\@chapposの初期値は\postchaptername(章)です。
\appendixは\@chapappを\appendixnameに,\@chapposを空に再定義します。
[2003-03-02]\@secappは外しました。
1553%<book|report>\newcommand{\@chapapp}{\prechaptername}
1554%<book|report>\newcommand{\@chappos}{\postchaptername}
■前付,本文,後付 本のうち章番号があるのが「本文」,それ以外が「前付」「後付」です。
\frontmatter ページ番号をローマ数字にし,章番号を付けないようにします。
1555%<*book|report>
1556\newcommand\frontmatter{%
1557 \if@openright
1558 \cleardoublepage
1559 \else
1560 \clearpage
1561 \fi
1562 \@mainmatterfalse
1563 \pagenumbering{roman}}
\mainmatter ページ番号を算用数字にし,章番号を付けるようにします。
1564\newcommand\mainmatter{%
1565% \if@openright
1566 \cleardoublepage
1567% \else
1568% \clearpage
1569% \fi
1570 \@mainmattertrue
1571 \pagenumbering{arabic}}
\backmatter 章番号を付けないようにします。ページ番号の付け方は変わりません。
1572\newcommand\backmatter{%
1573 \if@openright
1574 \cleardoublepage
1575 \else
1576 \clearpage
1577 \fi
1578 \@mainmatterfalse}
1579%</book|report>
■部
\part 新しい部を始めます。
\secdefを使って見出しを定義しています。このマクロは二つの引数をとります。
\secdef{星なし}{星あり} 星なし *のない形の定義です。
星あり *のある形の定義です。
\secdefは次のようにして使います。
\def\chapter { ... \secdef \CMDA \CMDB }
\def\CMDA [#1]#2{....} % \chapter[...]{...} の定義
\def\CMDB #1{....} % \chapter*{...} の定義 まずbook クラス以外です。
1580%<*!book&!report>
1581\newcommand\part{%
1582 \if@noskipsec \leavevmode \fi
1583 \par
1584 \addvspace{4ex}%
1585 \if@english \@afterindentfalse \else \@afterindenttrue \fi
1586 \secdef\@part\@spart}
1587%</!book&!report>
bookスタイルの場合は,少し複雑です。
1588%<*book|report>
1589\newcommand\part{%
1590 \if@openright
1591 \cleardoublepage
1592 \else
1593 \clearpage
1594 \fi
1595 \thispagestyle{empty}% 欧文用標準スタイルでは plain
1596 \if@twocolumn
1597 \onecolumn
1598 \@restonecoltrue
1599 \else
1600 \@restonecolfalse
1601 \fi
1602 \null\vfil
1603 \secdef\@part\@spart}
1604%</book|report>
\@part 部の見出しを出力します。\bfseriesを\headfontに変えました。
bookクラス以外ではsecnumdepthが−1 より大きいとき部番号を付けます。
1605%<*!book&!report>
1606\def\@part[#1]#2{%
1607 \ifnum \c@secnumdepth >\m@ne
1608 \refstepcounter{part}%
1609 \addcontentsline{toc}{part}{%
1610 \prepartname\thepart\postpartname\hspace{1\jsZw}#1}%
1611 \else
1612 \addcontentsline{toc}{part}{#1}%
1613 \fi
1614 \markboth{}{}%
1615 {\parindent\z@
1616 \raggedright
1617 \interlinepenalty \@M
1618 \normalfont
1619 \ifnum \c@secnumdepth >\m@ne
1620 \Large\headfont\prepartname\thepart\postpartname
1621 \par\nobreak
1622 \fi
1623 \huge \headfont #2%
1624 \markboth{}{}\par}%
1625 \nobreak
1626 \vskip 3ex
1627 \@afterheading}
1628%</!book&!report>
bookクラスではsecnumdepthが−2より大きいとき部番号を付けます。
1629%<*book|report>
1630\def\@part[#1]#2{%
1631 \ifnum \c@secnumdepth >-2\relax
1632 \refstepcounter{part}%
1633 \addcontentsline{toc}{part}{%
1634 \prepartname\thepart\postpartname\hspace{1\jsZw}#1}%
1635 \else
1636 \addcontentsline{toc}{part}{#1}%
1637 \fi
1638 \markboth{}{}%
1639 {\centering
1640 \interlinepenalty \@M
1641 \normalfont
1642 \ifnum \c@secnumdepth >-2\relax
1643 \huge\headfont \prepartname\thepart\postpartname
1644 \par\vskip20\p@?
1645 \fi
1646 \Huge \headfont #2\par}%
1647 \@endpart}
1648%</book|report>
\@spart 番号を付けない部です。
1649%<*!book&!report>
1650\def\@spart#1{{%
1651 \parindent \z@ \raggedright
1652 \interlinepenalty \@M
1653 \normalfont
1654 \huge \headfont #1\par}%
1655 \nobreak
1656 \vskip 3ex
1657 \@afterheading}
1658%</!book&!report>
1659%<*book|report>
1660\def\@spart#1{{%
1661 \centering
1662 \interlinepenalty \@M
1663 \normalfont
1664 \Huge \headfont #1\par}%
1665 \@endpart}
1666%</book|report>
\@endpart \@partと\@spartの最後で実行されるマクロです。両面印刷のときは白ページを追加しま
す。二段組のときには,二段組に戻します。
1667%<*book|report>
1668\def\@endpart{\vfil\newpage
1669 \if@twoside
1670 \null
1671 \thispagestyle{empty}%
1672 \newpage
1673 \fi
1674 \if@restonecol
1675 \twocolumn
1676 \fi}
1677%</book|report>
■章
\chapter 章の最初のページスタイルは,全体がemptyでなければplainにします。また,\@topnum を0にして,章見出しの上に図や表が来ないようにします。
1678%<*book|report>
1679\newcommand{\chapter}{%
1680 \if@openright\cleardoublepage\else\clearpage\fi
1681 \plainifnotempty % 元: \thispagestyle{plain}
1682 \global\@topnum\z@
1683 \if@english \@afterindentfalse \else \@afterindenttrue \fi
1684 \secdef
1685 {\@omit@numberfalse\@chapter}%
1686 {\@omit@numbertrue\@schapter}}
\@chapter 章見出しを出力します。secnumdepthが0以上かつ\@mainmatterが真のとき章番号を出 力します。
1687\def\@chapter[#1]#2{%
1688 \ifnum \c@secnumdepth >\m@ne
1689 \if@mainmatter
1690 \refstepcounter{chapter}%
1691 \typeout{\@chapapp\thechapter\@chappos}%
1692 \addcontentsline{toc}{chapter}%
1693 {\protect\numberline
1694% %{\if@english\thechapter\else\@chapapp\thechapter\@chappos\fi}%
1695 {\@chapapp\thechapter\@chappos}%
1696 #1}%
1697 \else\addcontentsline{toc}{chapter}{#1}\fi
1698 \else
1699 \addcontentsline{toc}{chapter}{#1}%
1700 \fi
1701 \chaptermark{#1}%
1702 \addtocontents{lof}{\protect\addvspace{10\jsc@mpt}}%
1703 \addtocontents{lot}{\protect\addvspace{10\jsc@mpt}}%
1704 \if@twocolumn
1705 \@topnewpage[\@makechapterhead{#2}]%
1706 \else
1707 \@makechapterhead{#2}%
1708 \@afterheading
1709 \fi}
\@makechapterhead 実際に章見出しを組み立てます。\bfseriesを\headfontに変えました。
1710\def\@makechapterhead#1{%
1711 \vspace*{2\Cvs}% 欧文は50pt
1712 {\parindent \z@ \raggedright \normalfont
1713 \ifnum \c@secnumdepth >\m@ne
1714 \if@mainmatter
1715 \huge\headfont \@chapapp\thechapter\@chappos
1716 \par\nobreak
1717 \vskip \Cvs % 欧文は20pt
1718 \fi
1719 \fi
1720 \interlinepenalty\@M
1721 \Huge \headfont #1\par\nobreak
1722 \vskip 3\Cvs}} % 欧文は40pt
\@schapter \chapter*{...}コマンドの本体です。\chaptermarkを補いました。
1723\def\@schapter#1{%
1724 \chaptermark{#1}%
1725 \if@twocolumn
1726 \@topnewpage[\@makeschapterhead{#1}]%
1727 \else
1728 \@makeschapterhead{#1}\@afterheading
1729 \fi}
\@makeschapterhead 番号なしの章見出しです。
1730\def\@makeschapterhead#1{%
1731 \vspace*{2\Cvs}% 欧文は50pt
1732 {\parindent \z@ \raggedright
1733 \normalfont
1734 \interlinepenalty\@M
1735 \Huge \headfont #1\par\nobreak
1736 \vskip 3\Cvs}} % 欧文は40pt
1737%</book|report>
■下位レベルの見出し
\section 欧文版では\@startsectionの第4引数を負にして最初の段落の字下げを禁止しています
が,和文版では正にして字下げするようにしています。
段組のときはなるべく左右の段が狂わないように工夫しています。
1738\if@twocolumn
1739 \newcommand{\section}{%
1740%<jspf>\ifx\maketitle\relax\else\maketitle\fi
1741 \@startsection{section}{1}{\z@}%
1742%<!kiyou> {0.6\Cvs}{0.4\Cvs}%
1743%<kiyou> {\Cvs}{0.5\Cvs}%
1744% {\normalfont\large\headfont\@secapp}}
1745 {\normalfont\large\headfont\raggedright}}
1746\else
1747 \newcommand{\section}{%
1748 \if@slide\clearpage\fi
1749 \@startsection{section}{1}{\z@}%
1750 {\Cvs \@plus.5\Cdp \@minus.2\Cdp}% 前アキ 1751 {.5\Cvs \@plus.3\Cdp}% 後アキ
1752% {\normalfont\Large\headfont\@secapp}}
1753 {\normalfont\Large\headfont\raggedright}}
1754\fi
\subsection 同上です。
1755\if@twocolumn
1756 \newcommand{\subsection}{\@startsection{subsection}{2}{\z@}%
1757 {\z@}{\z@}%
1758 {\normalfont\normalsize\headfont}}
1759\else
1760 \newcommand{\subsection}{\@startsection{subsection}{2}{\z@}%
1761 {\Cvs \@plus.5\Cdp \@minus.2\Cdp}% 前アキ 1762 {.5\Cvs \@plus.3\Cdp}% 後アキ
1763 {\normalfont\large\headfont}}
1764\fi
\subsubsection
1765\if@twocolumn
1766 \newcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}%
1767 {\z@}{\z@}%
1768 {\normalfont\normalsize\headfont}}
1769\else
1770 \newcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}%
1771 {\Cvs \@plus.5\Cdp \@minus.2\Cdp}%
1772 {\z@}%
1773 {\normalfont\normalsize\headfont}}
1774\fi
\paragraph 見出しの後ろで改行されません。
段落のマーク(■)が必ず和文フォントで出力されるようにする。さらに、このマークを 変更可能にするため\jsParagraphMarkというマクロに切り出した。
\jsJaCharはstandard和文ドライバが読み込まれた場合は\jachar と同義になるが、
それ以外は何もしない。
1775\newcommand\jsParagraphMark{\jsJaChar{■}}
1776\ifx\bxjs@paragraph@mark\@undefined\else
1777 \long\edef\jsParagraphMark{\noexpand\jsJaChar{\bxjs@paragraph@mark}}
1778\fi
1779\let\jsJaChar\@empty
1780\if@twocolumn
1781 \newcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}%
1782 {\z@}{-1\jsZw}% 改行せず 1\jsZw のアキ
1783%<jspf> {\normalfont\normalsize\headfont}}
1784%<!jspf> {\normalfont\normalsize\headfont\jsParagraphMark}}
1785\else
1786 \newcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}%
1787 {0.5\Cvs \@plus.5\Cdp \@minus.2\Cdp}%
1788 {-1\jsZw}% 改行せず 1\jsZw のアキ
1789%<jspf> {\normalfont\normalsize\headfont}}
1790%<!jspf> {\normalfont\normalsize\headfont\jsParagraphMark}}
1791\fi
\subparagraph 見出しの後ろで改行されません。
1792\newcommand{\subparagraph}{\@startsection{subparagraph}{5}{\z@}%
1793 {\z@}{-1\jsZw}%
1794 {\normalfont\normalsize\headfont}}