Skip to content

Instantly share code, notes, and snippets.

@zr-tex8r
Last active August 28, 2024 14:48
Show Gist options
  • Save zr-tex8r/de6ea73e94ebfb9999908a0af144435f to your computer and use it in GitHub Desktop.
Save zr-tex8r/de6ea73e94ebfb9999908a0af144435f to your computer and use it in GitHub Desktop.
tcnicenumber: 素敵でかつ涼しそうなLaTeXのカウンタ出力命令🦆⛄
%%
%% This is file 'tcnicenumber.sty'.
%%
%% Copyright (c) 2024 Takayuki YATO (aka. "ZR")
%% GitHub: https://github.com/zr-tex8r
%% Twitter: @zr_tex8r
%%
%% This package is distributed under the MIT License.
%%
%% package declaration
\RequirePackage {expl3}
\ProvidesExplPackage {tcnicenumber} {2024-08-28} {0.2.8}
{nice number format}
%--------------------------------------- general
%% packages
\RequirePackage { scsnowman, tikzducks, graphicx }
%--------------------------------------- nice digits
%% \tcznnm@duck (protected)
% The duck as digit '2'.
\cs_new_protected:Npn \tcznnm@duck
{
\resizebox { 0.8em } { ! }
{
\tikz [ x = 1cm, y = 1cm ]
{
\duck
[
body = blue!80!green!40,
bill = green!30!black!50,
hat = blue!50!green,
]
}
}
}
%% \tcznnm@snowman (protected)
% The snowman as digit '8'. (NICE!)
\cs_new_protected:Npn \tcznnm@snowman
{
\makebox [ 0.8em ]
{
\scsnowman
[
scale = 1.28,
adjustbaseline,
hat = blue!80!green!75!black,
muffler = blue!50!green,
]
}
}
%--------------------------------------- format numbers
% \__tcznnm_format:n {<number>} (restricted expandable)
% Outputs the given number in the nice format.
\cs_new:Nn \__tcznnm_format:n
% Just map over digits.
{ \str_map_function:nN {#1} \__tcznnm_digit:n }
% \__tcznnm_digit:n {<digit>} (fully expandable)
% Outputs a digit.
\cs_new:Nn \__tcznnm_digit:n
{
\str_case:nnF {#1}
{% 2 and 8 are special.
{ 2 } { \__tcznnm_out:nnn { \tcznnm@duck } { 1F986 } { 2 } }
{ 8 } { \__tcznnm_out:nnn { \tcznnm@snowman } { 26C4 } { 8 } }
}% Otherwise print the plain digit.
{#1}
}
%% \__tcznnm_out:nnn {<in-typeset>} {<in-unicode>} {<in-pdfdoc>}
% (fully expandable)
% Outputs text properly according to the context.
\cs_new:Nn \__tcznnm_out:nnn
{
\cs_if_exist:NTF \texorpdfstring % with hyperref
{
\texorpdfstring {#1} % for typeset
% for PDF-strings (in unicode and in pdfdoc)
{ \ifpdfstringunicode { \unichar { "#2 } } {#3} }
}
{#1}% no hyperref
}
%--------------------------------------- public interface
%%<*> \tcnicenumber {<counter-name>}
% Outputs the current value of the counter in the nice format.
\NewExpandableDocumentCommand \tcnicenumber { m }
{ \exp_args:Ne \__tcznnm_format:n { \arabic {#1} } }
%% \@tcnicenumber <int-var> (restricted expandable)
% Outputs the input value in the nice format.
\cs_new:Npn \@tcnicenumber #1
{ \exp_args:NV \__tcznnm_format:n #1 }
%--------------------------------------- all done
\endinput
%% EOF
%#!lualatex
\documentclass[a4paper]{ltjsarticle}
% しおりに節番号を表示する
\usepackage[colorlinks,bookmarksnumbered]{hyperref}
\usepackage{tcnicenumber}
% 節番号を素敵にする
\renewcommand*{\thesection}{\tcnicenumber{section}}
% ページ番号も素敵にする
\pagenumbering{tcnicenumber}
\begin{document}
\section{TL;DR}
\ref{sec:snowman}節(\pageref{sec:snowman}ページ)は
\ref{sec:duck}節(\pageref{sec:duck}ページ)より素敵。
\section{アヒル}\label{sec:duck}
Quack!
\section{アレ}
\section{アレ}
\newpage
\section{アレ}
\section{アレ}
\section{アレ}
\section{ゆきだるま}\label{sec:snowman}
素敵。
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment