summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/coloring
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/coloring
Initial commit
Diffstat (limited to 'macros/latex/contrib/coloring')
-rw-r--r--macros/latex/contrib/coloring/README11
-rw-r--r--macros/latex/contrib/coloring/coloring-doc.pdfbin0 -> 26014 bytes
-rw-r--r--macros/latex/contrib/coloring/coloring-doc.tex99
-rw-r--r--macros/latex/contrib/coloring/coloring.sty115
4 files changed, 225 insertions, 0 deletions
diff --git a/macros/latex/contrib/coloring/README b/macros/latex/contrib/coloring/README
new file mode 100644
index 0000000000..ddae957505
--- /dev/null
+++ b/macros/latex/contrib/coloring/README
@@ -0,0 +1,11 @@
+Package coloring: define missing colors by their names
+Copyright (C) 2016 Zou Hu <zohooo@yeah.net>
+
+Please report bugs, problems, and suggestions via
+ https://github.com/zohooo/coloring
+
+The package may be distributed and/or modified under the conditions
+of the LaTeX Project Public License, either version 1.3 of this
+license or (at your option) any later version. The latest version
+of this license is in
+ http://www.latex-project.org/lppl.txt
diff --git a/macros/latex/contrib/coloring/coloring-doc.pdf b/macros/latex/contrib/coloring/coloring-doc.pdf
new file mode 100644
index 0000000000..6a31590dfe
--- /dev/null
+++ b/macros/latex/contrib/coloring/coloring-doc.pdf
Binary files differ
diff --git a/macros/latex/contrib/coloring/coloring-doc.tex b/macros/latex/contrib/coloring/coloring-doc.tex
new file mode 100644
index 0000000000..35672abc19
--- /dev/null
+++ b/macros/latex/contrib/coloring/coloring-doc.tex
@@ -0,0 +1,99 @@
+% -*- coding: utf-8 -*-
+% !TEX program = xelatex
+
+\documentclass[14pt]{beamer}
+
+\usepackage{coloring}
+\usetheme[color=green]{epyt} % https://www.ctan.org/pkg/epyt
+
+\usepackage{arev} % use arev sans font
+
+\hypersetup{
+ pdfpagemode={FullScreen},
+}
+
+\usepackage{listings}
+\lstset{basicstyle=\ttfamily\color{rgbx55}}
+
+\usepackage{tabu}
+
+\AtBeginDocument{
+ \setlength{\parskip}{5pt plus 1pt minus 1pt}
+ \setlength{\baselineskip}{19pt plus 1pt minus 1pt}
+ \setlength{\lineskiplimit}{4pt}
+ \setlength{\lineskip}{4pt}
+}
+
+\begin{document}
+
+\title{LaTeX Package Coloring}
+\author{zohooo@yeah.net}
+%\institute{https://github.com/zohooo/coloring}
+
+\begin{frame}%[plain]
+\transboxout
+\titlepage
+\end{frame}
+
+\begin{frame}[fragile]{Introduction}
+The \verb|coloring| package makes it possible to define colors automatically by their names.
+\begin{itemize}
+ \item It's useful in drawing a \verb|tikz| picture.
+ \item It's useful in designing a \verb|beamer| theme.
+\end{itemize}
+Using the package, you \alert{don't} need to write \verb|\definecolor| before using a color.
+\end{frame}
+
+\begin{frame}[fragile]{Example One: Gray Colors}
+When you write
+\begin{lstlisting}
+\textcolor{gray2}{Text}
+\end{lstlisting}
+The package will automatically define the following \alert{gray} color for you
+\begin{lstlisting}
+\definecolor{gray2}{gray}{0.2}
+\end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]{Example Two: RGB Colors}
+When you write
+\begin{lstlisting}
+\colorbox{rgb37x}{Text}
+\end{lstlisting}
+The package will automatically define the following \alert{rgb} color for you
+\begin{lstlisting}
+\definecolor{rgb37x}{rgb}{0.3,0.7,1.0}
+\end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]{Example Three: HSB Colors}
+When you write
+\begin{lstlisting}
+\colorlet{mycolor}{blue59}
+\end{lstlisting}
+The package will automatically define the following \alert{hsb} color for you
+\begin{lstlisting}
+\definecolor{blue59}{Hsb}{240,0.5,0.9}
+\end{lstlisting}
+You may add the following line to the preamble when using hsb colors
+\begin{lstlisting}
+\substitutecolormodel{hsb}{rgb}
+\end{lstlisting}
+\end{frame}
+
+\def\mycolor#1{\noindent\color{black}\fcolorbox{gray}{#199}{\strut#1}}
+\begin{frame}{HSB Colors}
+\begin{center}
+\begin{tabu}{|r|X||r|X|}\hline
+ Hue & Name & Hue & Name \\\hline
+ 0 & \mycolor{red} & 180 & \mycolor{cyan} \\\hline
+ 30 & \mycolor{brown} & 210 & \mycolor{azure} \\\hline
+ 60 & \mycolor{yellow} & 240 & \mycolor{blue} \\\hline
+ 90 & \mycolor{olive} & 270 & \mycolor{violet} \\\hline
+ 120 & \mycolor{green} & 300 & \mycolor{magenta} \\\hline
+ 150 & \mycolor{teal} & 330 & \mycolor{purple} \\\hline
+\end{tabu}
+\end{center}
+\end{frame}
+
+\end{document}
diff --git a/macros/latex/contrib/coloring/coloring.sty b/macros/latex/contrib/coloring/coloring.sty
new file mode 100644
index 0000000000..95b18964eb
--- /dev/null
+++ b/macros/latex/contrib/coloring/coloring.sty
@@ -0,0 +1,115 @@
+% -*- coding: utf-8 -*-
+
+\ProvidesPackage{coloring}[2016/05/11 v0.2]
+
+\RequirePackage{xcolor,etoolbox,xparse,l3regex}
+
+\makeatletter
+
+\def\colorring@hack#1{\@ifundefined{\string\color@#1}{\coloringdefine{#1}}{\relax}}
+
+% hacking \definecolor and \colorlet in xcolor
+\pretocmd{\@declaredcolor}{\colorring@hack{#1}}{}{}
+\pretocmd{\XC@col@rlet}{\colorring@hack{#4}}{}{}
+
+% hacking \define@key{beamerthc}{fg} and \define@key{beamerthc}{bg} in beamer
+\catcode`\#=12
+\def\coloring@hack@beamer{%
+ \pretocmd{\KV@beamerthc@fg}{\colorring@hack{#1}}{}{}%
+ \pretocmd{\KV@beamerthc@bg}{\colorring@hack{#1}}{}{}%
+}
+\catcode`\#=6
+\@ifclassloaded{beamer}{\coloring@hack@beamer}{}{}
+
+\makeatother
+
+\ExplSyntaxOn
+
+% local variables for gray colors
+\tl_new:N \l_coloring_gray_tl
+
+% local variables for rgb colors
+\tl_new:N \l_coloring_r_tl
+\tl_new:N \l_coloring_g_tl
+\tl_new:N \l_coloring_b_tl
+
+% local variables for hsb/hsv colors
+\int_new:N \l_coloring_h_int
+\tl_new:N \l_coloring_s_tl
+\tl_new:N \l_coloring_v_tl
+
+\clist_new:N \l_coloring_hue_name_clist
+\clist_set:Nn \l_coloring_hue_name_clist
+ {
+ red, % 0
+ brown, % 30
+ yellow, % 60
+ olive, % 90
+ green, % 120
+ teal, % 150
+ cyan, % 180
+ azure, % 210
+ blue, % 240
+ violet, % 270
+ magenta, % 300
+ purple % 330
+ }
+
+\NewDocumentCommand \coloringdefine { m }
+{
+ % define gray colors
+ \coloring_define_gray:n { #1 }
+ % define rgb colors
+ \coloring_define_rgb:n { #1 }
+ % define hsb colors
+ \int_set:Nn \l_coloring_h_int { 0 }
+ \clist_map_inline:Nn \l_coloring_hue_name_clist
+ {
+ \coloring_define_hsb:nnn { \l_coloring_h_int } { ##1 } { #1 }
+ \int_add:Nn \l_coloring_h_int { 30 }
+ }
+}
+
+\cs_new_protected_nopar:Npn \coloring_define_gray:n #1
+{
+ \regex_extract_once:nnNT { \A gray([0-9x]) \Z } { #1 } \l_coloring_temp_seq
+ {
+ \seq_pop_right:NN \l_coloring_temp_seq \l_coloring_gray_tl
+ \coloring_set_value:N \l_coloring_gray_tl
+ \definecolor {#1} {gray} {\l_coloring_gray_tl}
+ }
+}
+
+\cs_new_protected_nopar:Npn \coloring_define_rgb:n #1
+{
+ \regex_extract_once:nnNT { \A rgb([0-9x])([0-9x])([0-9x]) \Z } { #1 } \l_coloring_temp_seq
+ {
+ \seq_pop_right:NN \l_coloring_temp_seq \l_coloring_b_tl
+ \seq_pop_right:NN \l_coloring_temp_seq \l_coloring_g_tl
+ \seq_pop_right:NN \l_coloring_temp_seq \l_coloring_r_tl
+ \coloring_set_value:N \l_coloring_b_tl
+ \coloring_set_value:N \l_coloring_g_tl
+ \coloring_set_value:N \l_coloring_r_tl
+ \definecolor {#1} {rgb} {\l_coloring_r_tl, \l_coloring_g_tl, \l_coloring_b_tl}
+ }
+}
+
+\cs_new_protected_nopar:Npn \coloring_define_hsb:nnn #1 #2 #3
+{
+ \regex_extract_once:nnNT { \A #2([0-9x])([0-9x]) \Z } { #3 } \l_coloring_temp_seq
+ {
+ \seq_pop_right:NN \l_coloring_temp_seq \l_coloring_v_tl
+ \seq_pop_right:NN \l_coloring_temp_seq \l_coloring_s_tl
+ \coloring_set_value:N \l_coloring_v_tl
+ \coloring_set_value:N \l_coloring_s_tl
+ \definecolor {#3} {Hsb} {\int_use:N #1, \l_coloring_s_tl, \l_coloring_v_tl}
+ }
+}
+
+\cs_new_protected_nopar:Npn \coloring_set_value:N #1
+{
+ \tl_set:Nn \l_tmpa_tl { x }
+ \tl_if_eq:NNTF #1 \l_tmpa_tl { \tl_set:Nn #1 {1} } { \tl_set:Nx #1 {.#1} }
+}
+
+\ExplSyntaxOff