Skip to content

Instantly share code, notes, and snippets.

@zr-tex8r
Created January 9, 2012 13:26
Show Gist options
  • Save zr-tex8r/1582926 to your computer and use it in GitHub Desktop.
Save zr-tex8r/1582926 to your computer and use it in GitHub Desktop.
newprooflikestyle that is parallel to amsthm's newtheoremstyle
amsthm パッケージの \newtheoremstyle / \theoremstyle / \newtheorem
と同じ方式で、スタイルを変更した「証明型環境」を新たに定義できるようにする
機能を提供する。
- \newprooflikestyle でスタイルを定義. 引数の意味は最後(9盤目)の
ものがないことを除いて \newtheoremstyle と同じ.
- \prooflikestyle{<スタイル>}: 以降に定義する証明型環境のスタイルを指定.
- \newprooflike{<環境名>}{<ラベル>}: 証明型環境を定義.
- なお, 既存命令/環境の上書きは「proof」のみ可.
%
% bxproofstyle.sty
%
%% package declaration
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bxproofstyle}
%% preparations
\RequirePackage{amsthm}
%%--------------------------------------
%% \bxpy@style
% Current proof-like style. (macro)
\def\bxpy@style{plain}
%%<*> \newprooflikestyle{<name>}{<space above>}{<space below>}
% {<body font>}{<indent amount>}{<proof head font>}
% {<punctuation after head>}{<space after head>}
\newcommand{\newprooflikestyle}[8]{%
\toks@{#4}%
\def\@tempa{#8}\ifx\space\@tempa
\toks@\@xp{\the\toks@ \thm@headsep\fontdimen\tw@\font\relax}%
\else
\def\@tempb{\newline}%
\def\bxpy@tempa{\par}%
\ifx\@tempb\@tempa
\toks@\@xp{\the\toks@ \thm@headsep\z@skip
\def\thmheadnl{\newline}}%
\else\ifx\bxpy@tempa\@tempa
\toks@\@xp{\the\toks@ \thm@headsep\z@skip
\def\thmheadnl{\par}}%
\else
\toks@\@xp{\the\toks@ \thm@headsep#8\relax}%
\fi\fi
\fi
\begingroup
\thm@space@setup
\@defaultunits\dimen@#5\z@skip\relax\@nnil
\@defaultunits\@tempskipa#2\thm@preskip\relax\@nnil
\@defaultunits\@tempskipb#3\thm@postskip\relax\@nnil
\xdef\@gtempa{\thm@preskip\the\@tempskipa
\thm@postskip\the\@tempskipb
\parindent\the\dimen@\relax}%
\endgroup
\@temptokena\@xp{\@gtempa
\thm@headfont{#6}\thm@headpunct{#7}%
}%
\@xp\xdef\csname bxpy@s@#1\endcsname{\the\toks@ \the\@temptokena}%
}
%%<*> \prooflikestyle{<name>}
\newcommand{\prooflikestyle}[1]{%
\@ifundefined{bxpy@s@#1}{%
\PackageWarning{amsthm}{Unknown proofstyle `#1'}%
\def\bxpy@style{plain}%
}{%
\edef\bxpy@style{#1}%
}%
}
%% \bxpy@s@plain
% The 'plain' style uses the default values.
\def\bxpy@s@plain{}
%%<*> \newprooflike{<env name>}{<label>}
\newcommand{\newprooflike}{\bxpy@new@prooflike}
\def\bxpy@new@prooflike#1#2{%
\@xp\bxpy@ifdefinable\csname #1\endcsname{%
\global\@xp\let\csname end#1\endcsname\bxpy@endprooflike
\@xp\xdef\csname#1\endcsname{\@nx\bxpy@prooflike
{\@xp\@nx\csname bxpy@s@\bxpy@style\endcsname}{#2}}}%
}
%% \bxpy@ifdefinable\CS{<proc>}
% Same as \@ifdefinable except that "\proof" is treated as definable.
\def\bxpy@cs@proof{\proof}
\def\bxpy@ifdefinable#1{%
\def\bxpy@tempa{#1}%
\ifx\bxpy@tempa\bxpy@cs@proof
\expandafter\@firstofone
\else
\expandafter\@ifdefinable\expandafter#1%
\fi
}
%% \bxpy@prooflike
\def\bxpy@prooflike#1#2{%
\pushQED{\qed}%
\normalfont
\let\thmheadnl\relax
\thm@headfont{\itshape}%
\thm@headpunct{.}% add period after heading
\thm@headsep \labelsep
\thm@preskip=6\p@\@plus6\p@\relax
\thm@postskip=\thm@preskip
#1% style overrides
% Here vertical spacing is processed in normal way of trivlist
\topsep \thm@preskip
\def\bxpy@label{#2}%
\bxpy@prooflike@a
}
\def\bxpy@prooflike@a{%
\@ifnextchar[%]
{\bxpy@prooflike@b}{\bxpy@prooflike@a[\bxpy@label]}%
}
\def\bxpy@prooflike@b[#1]{%
\par \trivlist
\advance\@topsepadd-\thm@preskip %
\advance\@topsepadd\thm@postskip %
\item[\hskip\labelsep \the\thm@headfont
#1\@addpunct{\the\thm@headpunct}]%
\hskip-\labelsep \hskip\thm@headsep
\ifx\thmheadnl\relax\else
\leavevmode\thmheadnl
\fi
\ignorespaces
}
%% \bxpy@endprooflike
\def\bxpy@endprooflike{%
\popQED\endtrivlist\@endpefalse
}
%%--------------------------------------
\endinput
\documentclass[a4paper]{article}
\usepackage{bxproofstyle}
\newtheorem{theorem}{Theorem}
\newprooflikestyle{bastard}
{7.5pt}{9pt}{\sffamily}{8em}{\ahofont}{!}{\newline}
\newcommand*\ahofont{\usefont{OT1}{cmfr}{m}{it}}
\prooflikestyle{bastard}
\newprooflike{proofwww}{Proof}
\begin{document}
\begin{theorem}
God exists.
\end{theorem}
% A famous proof given by Euler.
\begin{proofwww}
Sir,
\[ \frac{a + b^n}{n} = x. \]
Repondez!
\end{proofwww}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment