Created
December 12, 2019 10:33
-
-
Save wtsnjp/c678e4ec3e1b5a5e72c43253736ebdc6 to your computer and use it in GitHub Desktop.
LaTeX: local class options
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% | |
%% This is file 'clsopts.sty'. | |
%% | |
%% Copyright 2019 Takuto ASAKURA (wtsnjp) | |
%% GitHub: https://github.com/wtsnjp | |
%% Twitter: @wtsnjp | |
%% | |
%% This package is distributed under the MIT License. | |
%% | |
%% package declaration | |
\NeedsTeXFormat{LaTeX2e} | |
\ProvidesPackage{clsopts}[2019/12/12 v0.1.0] | |
\RequirePackage{etoolbox} | |
%% preparations | |
\def\clop@pkgname{clsopts} | |
\def\clop@warn{\PackageWarningNoLine\clop@pkgname} | |
%--------------------------------------- register local class options | |
\def\clop@list{} | |
\def\clop@register#1{\edef\clop@list{#1,\clop@list}} | |
\DeclareOption*{\clop@register{\CurrentOption}} | |
\ProcessOptions\relax | |
%--------------------------------------- patches | |
\newif\ifclop@clsopt | |
\patchcmd{\@fileswith@pti@ns} | |
{% | |
\ifx#1\@clsextension | |
\ifx\@classoptionslist\relax | |
\xdef\@classoptionslist{\zap@space#2 \@empty}% | |
\def\reserved@a{% | |
\@onefilewithoptions#3[{#2}][{#4}]#1% | |
\@documentclasshook}% | |
\else | |
\def\reserved@a{% | |
\@onefilewithoptions#3[{#2}][{#4}]#1}% | |
\fi | |
\else | |
} | |
{% | |
\ifx#1\@clsextension | |
\ifx\@classoptionslist\relax | |
\edef\@classoptionslist{\zap@space#2 \@empty}% | |
\def\clop@classoptionslist{}% | |
\@for\clop@cur@opt:=\@classoptionslist\do{% | |
\clop@clsoptfalse | |
\@for\clop@lopt:=\clop@list\do{% | |
\ifx\clop@cur@opt\clop@lopt | |
\clop@clsopttrue | |
\fi} | |
\ifclop@clsopt\else | |
\edef\clop@classoptionslist{\clop@cur@opt,\clop@classoptionslist}% | |
\fi}% | |
\global\let\@classoptionslist\clop@classoptionslist | |
\def\reserved@a{% | |
\@onefilewithoptions#3[{\clop@list#2}][{#4}]#1% | |
\@documentclasshook}% | |
\else | |
\def\reserved@a{% | |
\@onefilewithoptions#3[{\clop@list#2}][{#4}]#1}% | |
\fi | |
\else | |
} | |
{\relax}{\clop@warn{Failed to patch the LaTeX kernel}} | |
%--------------------------------------- all done | |
\endinput | |
%% EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%#!pdflatex | |
\RequirePackage[draft,fleqn]{clsopts} % draft,fleqn: only for the class | |
\documentclass[a4paper,12pt]{article} % a4paper,12pt: for both the class and packages | |
\usepackage{hyperref} | |
\makeatletter | |
\parindent=0pt | |
\edef\clsopts{\ifx\@classoptionslist\relax EMPTY\else\@classoptionslist\fi} | |
\makeatother | |
\begin{document} | |
\hbox to\textwidth{\hskip\textwidth Hello!} | |
\[ | |
E=mc^2 | |
\] | |
\href{https://google.com}{Google} | |
Global options: \clsopts | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment