Skip to content

Instantly share code, notes, and snippets.

@zr-tex8r
Created July 1, 2023 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zr-tex8r/163f166019acda0698abf0295bd2523e to your computer and use it in GitHub Desktop.
Save zr-tex8r/163f166019acda0698abf0295bd2523e to your computer and use it in GitHub Desktop.
LaTeX: Hack for top-level color changes with dvipdfmx
% bxdpx-tchack.sty
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bxdpx-tchack}[2023/07/01 v0.1]
\def\bxqcx@pkgname{bxdpx-tchack}
\ifx\currentgrouplevel\@undefined
\PackageError\bxqcx@pkgname{e-TeX extension not supported}\@ehc
\expandafter\endgroup\fi\relax
\AtBeginDocument{%
\def\bxqcx@org@set@color{\special{color pop}}
\ifx\bxqcx@org@set@color\reset@color
\set@color % push once
\let\bxqcx@org@set@color\set@color
\def\set@color{%
\ifnum\currentgrouplevel>\z@ \bxqcx@org@set@color
\else \special{color pop}\special{color push \current@color}%
\fi}%
\else
\PackageError\bxqcx@pkgname{Unsupported color driver}\@ehc
\fi}
%% EOF
% upLaTeX + dvipdfmx (essential)
\documentclass[dvipdfmx]{jsarticle}
\usepackage{xcolor}
\colorlet{R}{red}\colorlet{B}{blue}\colorlet{G}{green!50!black}
\usepackage{bxdpx-tchack}
\newcommand*\cS[1]{\color{#1}☃\color{black}}
\newcommand*\cNice[7]{%
\cS{#1}っ\cS{#2}\cS{#3}\cS{#4}っ\cS{#5}っ \cS{#6}っっ♪\cS{#7}っっ♪}
\newcommand*\cNicePar{%
\cNice{R}{B}{R}{G}{B}{R}{R} \cNice{B}{B}{G}{R}{G}{B}{B}\par
\cNice{G}{R}{R}{R}{B}{G}{G} \cNice{R}{G}{R}{B}{G}{R}{R}\par}
\begin{document}
\cNicePar \cNicePar \cNicePar \cNicePar \cNicePar
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment