From 763f76877a8a6d4a74e09c3f410bff78d5e37813 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E0=A4=A8=E0=A4=BF=E0=A4=B0=E0=A4=82=E0=A4=9C=E0=A4=A8?=
 <hi.niranjan@pm.me>
Date: Wed, 26 Jan 2022 22:45:23 +0530
Subject: [PATCH 14/14] using counters for conditionals

---
 tipauni/tipauni.dtx | 87 ++++++++++++++++++++++++++++++---------------
 1 file changed, 59 insertions(+), 28 deletions(-)

diff --git a/tipauni/tipauni.dtx b/tipauni/tipauni.dtx
index 7052b76..054a982 100644
--- a/tipauni/tipauni.dtx
+++ b/tipauni/tipauni.dtx
@@ -475,6 +475,10 @@ Unicode characters with TIPA commands]
   \documentfontfalse
   \charissilfalse
   \preservefonttrue
+  \ifnum\value{specialsettings}=1%
+    \setcounter{specialsettings}{0}%
+  \else
+  \fi
 }
 \DeclareOptionX{fontspecoptions}{%
   \edef\tipauni@font@options{#1}%
@@ -490,42 +494,69 @@ Unicode characters with TIPA commands]
   \fi
   \fontoptionsfalse
 }
+\newcounter{specialsettings}
 \DeclareOptionX{documentfont}{%
-  \edef\tipauni@temp{#1}
-  \ifx\tipauni@temp\@empty
-    \ifdocumentfont
-    \else
+  \edef\tipauni@temp{#1}%
+  \ifx\tipauni@font\undefined
+    \ifx\tipauni@temp\@empty
       \ifpreservefont
-        \PackageWarningNoLine{tipauni}{%
-          1. The `preservefont' option is active.\MessageBreak
-          2. The `documentfont' option has no value.\MessageBreak
-          Your document will be compiled with the default\MessageBreak
-          font-family of (Xe/Lua)LaTeX, i.e., Latin Modern\MessageBreak
-          unless another font is set with tipauni-external\MessageBreak
-          methods%
-        }%
+        \setcounter{specialsettings}{0}%
         \documentfontfalse
         \charissilfalse
       \else
-        \PackageWarningNoLine{tipauni}{%
-          The `documentfont' option has no value. Your\MessageBreak
-          document will be compiled with the default\MessageBreak
-          font-family of package tipauni, i.e., Charis SIL\MessageBreak
-          unless another font is set with tipauni-external\MessageBreak
-          methods%
-        }%
-        \documentfonttrue
-        \charissiltrue
+        \setcounter{specialsettings}{1}%
+        \documentfontfalse
+        \charissilfalse
       \fi
+    \else
+      \ifnum\value{specialsettings}<3%
+        \setcounter{specialsettings}{3}%
+      \else
+      \fi
+      \edef\tipauni@font{#1}%
+      \documentfonttrue
+      \charissilfalse
     \fi
   \else
-    \edef\tipauni@font{#1}
-    \documentfonttrue
-    \charissilfalse
+    \setcounter{specialsettings}{3}%
   \fi
 }
 \DeclareOptionX{incompatible}{\nontipaignoretrue}
 \ProcessOptionsX\relax
+\ifnum\value{specialsettings}=0%
+  \PackageWarningNoLine{tipauni}{%
+    1. The `preservefont' option is active.\MessageBreak
+    2. The `documentfont' option has no value.\MessageBreak
+    Your document will be compiled with the default\MessageBreak
+    font-family of (Xe/Lua)LaTeX, i.e., Latin Modern\MessageBreak
+    unless another font is set with tipauni-external\MessageBreak
+    methods%
+  }%
+\else
+  \ifnum\value{specialsettings}=1%
+    \PackageWarningNoLine{tipauni}{%
+      The `documentfont' option has no value. Your\MessageBreak
+      document will be compiled with the default\MessageBreak
+      font-family of (Xe/Lua)LaTeX, i.e., Latin Modern\MessageBreak
+      unless another font is set with tipauni-external\MessageBreak
+      methods%
+    }%
+  \fi
+  \ifnum\value{specialsettings}=2%
+    \PackageWarningNoLine{tipauni}{%
+      A `documentfont' option has no value, but you have\MessageBreak
+      used another `documentfont' option with a value\MessageBreak
+      before it, so the value of that option will be used\MessageBreak
+      as the main font of this document unless another font\MessageBreak
+      is set with tipauni-external methods. The font being\MessageBreak
+      currently loaded is: \tipauni@font%
+    }%
+  \else
+  \fi
+  \ifnum\value{specialsettings}=3%
+  \else
+  \fi
+\fi
 \ifcharissil
   \def\tipauni@font{CharisSIL}%% https://ctan.org/pkg/charissil
 \else
@@ -537,10 +568,10 @@ Unicode characters with TIPA commands]
         option or the default Charis SIL font ineffective.\MessageBreak
         An active font loaded with package fontspec is\MessageBreak
         necessary for `fontspecoptions' to take effect.\MessageBreak
-        Please use the documentfont option or remove the\MessageBreak
-        `preservefont' option to make `fontpecoptions'\MessageBreak
-        effective. Currently the ignored fontpsec option(s)\MessageBreak
-        is (are) as follows:\MessageBreak
+        Please use the documentfont option after preservefont\MessageBreak
+        or remove the `preservefont' option to make\MessageBreak
+        `fontpecoptions' effective. Currently the ignored\MessageBreak
+        fontpsec option(s) is (are) as follows:\MessageBreak
         \tipauni@font@options
       }%
     \fi
-- 
2.20.1

