Skip to content

Instantly share code, notes, and snippets.

@aminophen
Last active April 29, 2020 12:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aminophen/387797f1969bce23d90e28dfe2dc8238 to your computer and use it in GitHub Desktop.
Save aminophen/387797f1969bce23d90e28dfe2dc8238 to your computer and use it in GitHub Desktop.
パッケージ (.sty) 単独でもコンパイルできる、まるで .dtx のようなパッケージの実装例
% \iffalse meta-comment
%
% Copyright (c) 2016 Hironobu Yamashita (@aminophen)
%
%%%%%%%% ^^A driver-like trick using catcode difference
%
% This file `tcstyalone.sty' is a normal LaTeX package, so
% \RequirePackage{tcstyalone}
% and
% \usepackage{tcstyalone}
% works. However, it can also be typeset alone:
% latex tcstyalone.sty
% for convenience.
%
\ifx\undefined\@undefined\relax
% case 1: This file must be a normal package
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{tcstyalone}[2016/06/25 v1.0 Sample of DTX-like package]
\else
% case 2: This file pretends to be a document
\documentclass{ltxdoc}
\usepackage{tcstyalone}% if you like
\title{Example of DTX-like package}
\author{Hironobu Yamashita}
\begin{document}
\maketitle
\DocInput{tcstyalone.sty}
\end{document}
\fi % ^^A In case 2, this \fi comes after \end{document}
% ^^A so it has no effect.
% \fi ^^A This \fi corresponds to \iffalse, and another
% ^^A \fi is required for \ifx, see below;)
%
%%%%%%%% ^^A trick end
%
% \fi
%
% \section{Definition of Snowman}
%
% \begin{macro}{\Snowman}
% We define |\Snowman|. Here is the result: \Snowman
% \changes{v???}{????/??/??}{This is a snowman.}
% \begin{macrocode}
\def\Snowman{This is a snowman.}
% \end{macrocode}
% \end{macro}
%
\endinput
@aminophen
Copy link
Author

解説はブログ参照。

@cmplstofB
Copy link

(aminophen氏とは無関係の者です)
aminophen氏がブログを変更されておられますので,リンクが切れてしまっています。
新URLの方を参照するといいと思います。
旧: http://d.hatena.ne.jp/acetaminophen/20160625/1466869059
新: http://acetaminophen.hatenablog.com/entry/2016/06/25/003739

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment