Skip to content

Instantly share code, notes, and snippets.

@kauplan
Created May 25, 2020 13:01
Show Gist options
  • Save kauplan/63a0741d821057ded9e8750214dee02d to your computer and use it in GitHub Desktop.
Save kauplan/63a0741d821057ded9e8750214dee02d to your computer and use it in GitHub Desktop.
'\ifx' をcontrol sequence化すると、必要な '\fi' の数が1個だけになる
% -*- coding: utf-8 -*-
\documentclass[dvipdfmx,uplatex]{jsarticle}
\usepackage[deluxe]{otf}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\newcommand{\ifempty}[1]{%
\edef\tempval{#1}%
\ifx\tempval\empty%
}
\def\sampleflagA{Y}
\def\sampleflagB{Y}
\def\sampleflagC{}
%%% '\ifx' を使うと終わりの '\fi' が複数個必要
\ifx\sampleflagA\empty
\newcommand{\samplecommand}{A}
\ifx\sampleflagB\empty
\newcommand{\samplecommand}{B}
\ifx\sampleflagC\empty
\newcommand{\samplecommand}{C}
\else
\newcommand{\samplecommand}{X}
\fi\fi\fi %← '\ifx' の数だけ '\fi' が必要
%%% '\ifx' をcontrol sequenceにすると終わりの '\fi' が1個だけ
\ifempty{\sampleflagA}
\newcommand{\samplecommand}{A}
\else\ifempty{\sampleflagB}
\newcommand{\samplecommand}{B}
\else\ifempty{\sampleflagC}
\newcommand{\samplecommand}{C}
\else
\newcommand{\samplecommand}{X}
\fi %← 必要な '\fi' は1個だけ
\begin{document}
本文\par
\samplecommand
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment