%%
%% This is file 'bxtexlogo.sty'.
%%
%% Copyright (c) 2016-2026 Takayuki YATO (aka. "ZR")
%%   GitHub:   https://github.com/zr-tex8r
%%   Twitter:  @zr_tex8r
%%
%% This package is distributed under the MIT License.
%%

%% package declaration
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bxtexlogo}[2026/05/15 v0.7a]

%% preparation
\def\bxlg@pkgname{bxtexlogo}
\providecommand\bxDebug[1]{}

% NOTE. The sets of primary and secondary logos
% are frozen until v1.0.

%--------------------------------------- general

%% packages
\IfFileExists{hologo.sty}{%
\RequirePackageWithOptions{hologo}
}{}

%% hologo import list
\def\bxlg@hologo@import@primary{%
  AmSLaTeX,AmSTeX,BibTeX,ConTeXt,eTeX,LaTeX,LaTeXe,%
  LuaLaTeX,LuaTeX,LyX,METAFONT,METAPOST,pdfTeX,pdfLaTeX,%
  TeX,XeLaTeX,XeTeX}
\def\bxlg@hologo@import@secondary{%
  HanTheThanh,KOMAScript,LaTeXTeX,NTS,PiCTeX,SageTeX,%
  SLiTeX,teTeX,TTH}
\def\bxlg@hologo@import@nolevel{%
  (La)TeX,biber,BibTeX8,emTeX,ExTeX,iniTeX,La,LaTeX2e,%
  LaTeX3,MetaFun,MetaPost,MiKTeX,OzMF,OzMP,OzTeX,OzTtH,%
  PCTeX,PiC,plainTeX,SliTeX,teTeX,TeX4ht,virTeX,VTeX,Xe}
\@onlypreamble\bxlg@hologo@import@primary
\@onlypreamble\bxlg@hologo@import@secondary
\@onlypreamble\bxlg@hologo@import@nolevel

%% constants
\def\bxlg@@star{*}
\def\bxlg@@dblstar{**}

%% variables
\newif\ifbxlg@ok
\newif\ifbxlg@forced
\newif\ifbxlg@onego
\newif\ifbxlg@hologo@ok

%% unique tokens
\def\bxlg@end{\bxlg@end@}
\def\bxlg@mk{\bxlg@mk@}

%% errors
\def\bxlg@err@ukval#1{\PackageError\bxlg@pkgname
 {Unknown value '#1'}%
 {\@eha}}
\def\bxlg@err@uknam#1{\PackageError\bxlg@pkgname
 {Unknown logo name '#1'}%
 {\@ehc}}

%% \bxlg@cond\ifXXX..\fi{<T>}{<F>}
\@gobbletwo\if\if \def\bxlg@cond#1\fi{%
  #1\expandafter\@firstoftwo
  \else \expandafter\@secondoftwo\fi}

%% \bxlg@jump@exit...\bxlg@exit
\@gobble\if \long\def\bxlg@jump@exit#1\bxlg@exit{\fi}
\let\bxlg@exit\relax

%% \bxlg@logo@do{<LaTeX-form>}{<text-form>}
% Uses \texorpdfstring if available.
\def\bxlg@logo@do{%
  \bxlg@cond\ifx\texorpdfstring\@undefined\fi
      {\@firstoftwo}{\texorpdfstring}}

%% \bxlg@hologo{<name>}
% Forwards to \hologo if it is available; otherwise does the original
% fallback procedure.
\@ifundefined{hologo}{%
  \bxlg@hologo@okfalse
  \def\bxlg@hologo#1{%
    \expandafter\bxlg@hologo@a\csname bxlg@holf@@#1\endcsname{#1}}
  \def\bxlg@hologo@a#1#2{%
    \bxlg@logo@do{%
      \bxlg@hologo@do#1{#2}%
    }{\ifx#1\relax ?#2?\else #2\fi}}
  \DeclareRobustCommand*\bxlg@hologo@do[2]{%
    \PackageError\bxlg@pkgname{%
      \ifx#1\relax
        Unknown logo '#2'%
      \else
        The logo '#2' is not available,\MessageBreak
        because the package 'hologo' is not found%
      \fi
    }{\@ehc}%
    \ifx#1\relax ?#2?\else #2\fi}
  % For compatibility with old versions, \hologo itself as fallback
  % is alsod defined. This feature will be abolished in future.
  \@namedef{hologo}{\bxlg@hologo}
}{%else
  \bxlg@hologo@oktrue
  \def\bxlg@hologo{\hologo}
}
%%<+> \bxtexlogoHologo{<name>}
% Just a public name for \bxlg@hologo.
\def\bxtexlogoHologo{\bxlg@hologo}

%--------------------------------------- registration

%% constants
\chardef\bxlg@level@@primary=1
\chardef\bxlg@level@@secondary=2
\chardef\bxlg@level@@=0 % no-level (not for bulk import)

%% variables
\let\bxlg@list\@empty
%\[bxlg@flag@@<name>]% level value
%\[bxlg@logo@@<name>]% real definition
%\[bxlg@lcmd@@<name>]% core definition
%\[bxlg@holf@@<name>]% hologo flag

%%<+> \bxtexlogoDeclare{<level>}{<name>}[<text-form>]{<LaTeX-form>}
% If [<text-form>] is omitted, it defaults to <name>.
% If <text-form> is empty, <LaTeX-form> is always used.
\@onlypreamble\bxtexlogoDeclare
\newcommand*\bxtexlogoDeclare[2]{%{<level>}{<name>}
  \@ifnextchar[%
   {\bxlg@declare@a{#1}{#2}}%
   {\bxlg@declare@a{#1}{#2}[#2]}}
\@onlypreamble\bxlg@declare@a
\def\bxlg@declare@a#1{%
  \begingroup
    \expandafter\bxlg@declare@b\csname bxlg@level@@#1\endcsname{#1}}
\@onlypreamble\bxlg@declare@b
\def\bxlg@declare@b#1#2#3[#4]{% \LEVEL{<level>}{<name>}[<text>]
  \ifx#1\relax
    \bxlg@err@ukval{#2}%
    \def\bxlg@next{\endgroup}%
  \else
    \g@addto@macro\bxlg@list{\do{#3}}%
    \ifnum#1>\z@
      \global\expandafter\let\csname bxlg@flag@@#3\endcsname#1\fi
    \def\bxlg@next{\bxlg@declare@c{#3}{#4}}%
  \fi
  \afterassignment\bxlg@next \toks@}% read {<LaTeX>}
\@onlypreamble\bxlg@declare@c
\def\bxlg@declare@c#1{%{<name>}
  \expandafter\bxlg@declare@d\csname bxlg@lcmd@@#1\expandafter
      \endcsname\csname bxlg@logo@@#1\endcsname}
\@onlypreamble\bxlg@declare@d
\def\bxlg@declare@d#1#2#3{%\LCMD\LOGO{<text>}
    \ifx\bxlg@mk#3\bxlg@mk \gdef#1{\protect#2}%
    \else \gdef#1{\bxlg@logo@do{\protect#2}{#3}}%
    \fi
    \xdef#2{\the\toks@}%
  \endgroup}

%% import from hologo
\def\bxlg@tmpa#1#2{%
  \expandafter\let\csname bxlg@holf@@#2\endcsname=t%
  % All hologo logos support PDF-strings.
  \bxtexlogoDeclare{#1}{#2}[]{\bxlg@hologo{#2}}}
\@for\bxlg@tmpb:=\bxlg@hologo@import@primary\do{%
  \edef\bxlg@next{\noexpand\bxlg@tmpa{primary}{\bxlg@tmpb}%
  }\bxlg@next}
\@for\bxlg@tmpb:=\bxlg@hologo@import@secondary\do{%
  \edef\bxlg@next{\noexpand\bxlg@tmpa{secondary}{\bxlg@tmpb}%
  }\bxlg@next}
\@for\bxlg@tmpb:=\bxlg@hologo@import@nolevel\do{%
  \edef\bxlg@next{\noexpand\bxlg@tmpa{}{\bxlg@tmpb}%
  }\bxlg@next}

%--------------------------------------- registry

%% very famous somewhere
\bxtexlogoDeclare{primary}{pTeX}{p\kern-.05em\TeX}
\bxtexlogoDeclare{primary}{epTeX}[e-pTeX]{%
  \mbox{\bxlg@epsilon-\bxlg@logo@@pTeX}}
\bxtexlogoDeclare{primary}{pLaTeX}[]{p\LaTeX}
\bxtexlogoDeclare{primary}{pLaTeXe}[]{p\LaTeXe}
\bxtexlogoDeclare{primary}{upTeX}{up\kern-.05em \TeX}
\bxtexlogoDeclare{primary}{eupTeX}[e-upTeX]{%
  \mbox{\bxlg@epsilon-\bxlg@logo@@upTeX}}
\bxtexlogoDeclare{primary}{upLaTeX}[]{up\LaTeX}
\bxtexlogoDeclare{primary}{upLaTeXe}[]{up\LaTeXe}
\bxtexlogoDeclare{primary}{JBibTeX}{%
  \leavevmode\lower.5ex\hbox{J}\bxlg@akern{-.15}\bxlg@hologo{BibTeX}}
\bxtexlogoDeclare{primary}{pBibTeX}[]{p\bxlg@hologo{BibTeX}}
\bxtexlogoDeclare{primary}{upBibTeX}[]{up\bxlg@hologo{BibTeX}}
\bxtexlogoDeclare{primary}{TikZ}{%
  Ti\bxtexlogoItalicOrSlant{k}Z\bxlg@nonuc}

%% old or not-so-famous
\bxtexlogoDeclare{secondary}{JTeX}{%
  \leavevmode\lower.5ex\hbox{J}\bxlg@akern{-.17}\TeX}
\bxtexlogoDeclare{secondary}{JLaTeX}{%
  \leavevmode\lower.5ex\hbox{J}\bxlg@akern{-.15}\LaTeX}
\bxtexlogoDeclare{secondary}{pTeXsT}{%
  p\kern-.21em \TeX\kern-.10em s\kern-.21em T\bxlg@nonuc}
\bxtexlogoDeclare{secondary}{XyM}{%
  X\kern-.30em %
  \smash{\raise.50ex\hbox to0.8em{\hss\bxlg@Grk{7}\hss}}%
  \kern -.30em M}
\bxtexlogoDeclare{secondary}{XyMTeX}{%
  \bxlg@logo@@XyM \kern-.1em \TeX}
\bxtexlogoDeclare{secondary}{KET}{%
  K\kern-.16em \lower.5ex\hbox{E}\kern-.12emT}
\bxtexlogoDeclare{secondary}{KETpic}{%
  \bxlg@logo@@KET pic}
\bxtexlogoDeclare{secondary}{logoOmega}[Omega]{\bxlg@Grk{10}}
\bxtexlogoDeclare{secondary}{logoLambda}[Lambda]{\bxlg@Grk{3}}
\bxtexlogoDeclare{secondary}{logoAleph}[Aleph]{\bxlg@Aleph}
\bxtexlogoDeclare{secondary}{logoLamed}[Lamed]{\bxlg@Lamed}
\bxtexlogoDeclare{secondary}{LaTeXiT}{%
  \LaTeX \kern-.09em
  \raise.36ex\hbox{i}\kern-.06em T\bxlg@nonuc}
\bxtexlogoDeclare{secondary}{LaTeXML}{%
  \bxlg@hologo{La}\kern-.15em T\kern-.1667em \lower.5ex\hbox{E}%
  \bxlg@smaller{XML}\bxlg@nonuc}
\bxtexlogoDeclare{secondary}{HeVeA}{%
  H\kern-.08em
  \begingroup \setbox\z@\hbox{H}%
    \vbox to\ht\z@{\vss\hbox{\bxlg@smaller{E}}\vss}%
    \kern-.07em V\kern-.08em
    \vbox to\ht\z@{\vss\hbox{\bxlg@smaller{E}}\vss}%
  \endgroup \kern-.09em
  A\bxlg@nonuc}
\bxtexlogoDeclare{secondary}{KaTeX}{%
  K\kern-.26em
  \begingroup \setbox\z@\hbox{T}%
    \vbox to\ht\z@{\kern.05em \hbox{\bxlg@smaller{A}}\vss}%
  \endgroup
  \kern-.23em \TeX}
\bxtexlogoDeclare{secondary}{ApTeX}{A\kern-.08em \bxlg@logo@@pTeX}
\bxtexlogoDeclare{secondary}{DVIPDFMx}{% obsolete logo
  DVI\-PDFM\bxtexlogoItalicOrSlant{x}}
\bxtexlogoDeclare{secondary}{OpTeX}{Op\kern-.05em \TeX}
\bxtexlogoDeclare{secondary}{CSTUG}{\leavevmode
  \bxlg@cal{C}\kern-.3em \lower.67ex\hbox{\bxlg@cal{S}}%
  \kern-.145em TUG\bxlg@nonuc}
\bxtexlogoDeclare{secondary}{HiTeX}[]{Hi\TeX}
\bxtexlogoDeclare{secondary}{TeXXeT}[TeX--XeT]{%
  \TeX-\textbf{-}\bxlg@logo@@XeT}

%% fancy things (Not!)
\bxtexlogoDeclare{secondary}{BaSiX}{%
  B\kern-.18em \lower.45ex\hbox{A}\kern-.15em %
  S\kern-.1em \lower.45ex\hbox{I}\kern-.1em X\bxlg@nonuc}
\bxtexlogoDeclare{secondary}{logoon}[on]{\bxtexlogoSmcp{on}}
\bxtexlogoDeclare{secondary}{TeXonLaTeX}[TeX on LaTeX]{%
  \TeX\ \bxlg@logo@@logoon\ \LaTeX}
\bxtexlogoDeclare{secondary}{OneTeX}[1TeX]{%
  \bxlg@One\kern-0.2em \TeX}
\bxtexlogoDeclare{secondary}{SuyahTeX}{\bxlg@Suyah\TeX}

%% logos of "no-level"
\bxtexlogoDeclare{}{LuaMetaTeX}{%
  LuaMeta\kern-.083333em \TeX}
\bxtexlogoDeclare{}{HiLaTeX}[]{Hi\LaTeX}
\bxtexlogoDeclare{}{XeT}{%
  \textbf{\bxtexlogoReflect{\TeX}{XeT}}\bxlg@nonuc}
\bxtexlogoDeclare{}{e}{\bxlg@epsilon}
\bxtexlogoDeclare{}{lowe}[e]{\bxlg@in@math{_{\textstyle\varepsilon}}}
\bxtexlogoDeclare{}{1TeX}{\bxlg@logo@@OneTeX}%alias
\bxtexlogoDeclare{}{LuahbTeX}[LuaHBTeX]{% experimental
  Lua\bxtexlogoSmcp{hb}\kern-.05em \TeX}
\bxtexlogoDeclare{}{arara}{\bxlg@arara}
\bxtexlogoDeclare{}{One}[1]{\bxlg@One}
\bxtexlogoDeclare{}{Suyah}{\bxlg@Suyah}
\bxtexlogoDeclare{}{Yukidaruma}{\bxlg@Yukidaruma}
\bxtexlogoDeclare{}{YukidarumaTeX}{\bxlg@Yukidaruma\TeX}

%% other than TeX
\bxtexlogoDeclare{secondary}{SATySFi}{%
  S\kern-0.1em A\kern-0.18em T\kern-0.22em
  \lower0.2em\hbox{Y}\kern-0.08em
  S\kern-0.04em F\kern-0.12em
  \lower0.2em\hbox{I}}

%--------------------------------------- import

%% variables
\let\bxlg@name\relax
\let\bxlg@pfx\relax

%%<*> \bxtexlogoimport{<spec-str>}
\@onlypreamble\bxtexlogoimport
\newcommand*\bxtexlogoimport{%
  \bxlg@onegotrue
  \bxlg@import}
\@onlypreamble\bxtexlogoImport
\newcommand*\bxtexlogoImport{%
  \bxlg@onegofalse
  \bxlg@import}
\@onlypreamble\bxlg@import
\def\bxlg@import#1{%
  \global\let\bxlg@default@import\relax
  \@for\bxlg@name:=#1\do{%
    \begingroup
      \bxlg@split@name
      \ifx\bxlg@name\bxlg@@star
        \bxlg@import@all\bxlg@level@@primary
      \else\ifx\bxlg@name\bxlg@@dblstar
        \bxlg@import@all\bxlg@level@@secondary
      \else\expandafter\ifx\csname bxlg@logo@@\bxlg@name\endcsname\relax
        \bxlg@err@uknam\bxlg@name
      \else
        \bxlg@import@one\bxlg@name
      \fi\fi\fi
    \endgroup}}

%% \bxlg@import@one
\@onlypreamble\bxlg@import@one
\def\bxlg@import@one#1{%
  \expandafter\ifx\csname\bxlg@pfx#1\endcsname\relax
    \bxlg@oktrue
  \else\ifbxlg@forced
    \bxlg@oktrue
    \PackageWarning\bxlg@pkgname
     {'\@backslashchar\bxlg@pfx#1' redefined}%
  \else \bxlg@okfalse
  \fi\fi
  \ifbxlg@onego
    \global\expandafter\let\csname bxlg@flag@@#1\endcsname\@undefined
  \fi
  \ifbxlg@ok
    \expandafter\bxlg@import@one@a\csname\bxlg@pfx#1\expandafter
        \endcsname\csname bxlg@lcmd@@#1\endcsname
  \fi}
\def\bxlg@import@one@a#1#2{%
  \bxDebug{defined: \string#1}%
  \global\let#1#2}

%% \bxlg@import@all{<level>}
\@onlypreamble\bxlg@import@all
\def\bxlg@import@all#1{%
  \let\bxlg@tmpb#1%
  \let\do\bxlg@import@all@do \bxlg@list}
\@onlypreamble\bxlg@import@all@do
\def\bxlg@import@all@do#1{%
  \expandafter\ifx\csname bxlg@flag@@#1\endcsname\bxlg@tmpb
    \bxlg@import@one{#1}%
  \fi}

%% \bxlg@split@name
\@onlypreamble\bxlg@split@name
\def\bxlg@split@name{%
  \bxlg@split@name@a+\ifx\bxlg@pfx\relax
    \bxlg@split@name@a-\ifx\bxlg@pfx\relax
      \bxlg@forcedfalse \let\bxlg@pfx\@empty
    \else \bxlg@forcedfalse
    \fi
  \else \bxlg@forcedtrue
  \fi}
\@onlypreamble\bxlg@split@name@a
\def\bxlg@split@name@a#1{%
  \def\bxlg@next##1#1##2\bxlg@end{\bxlg@split@name@b{##1}{##2}}%
  \expandafter\bxlg@next\bxlg@name\bxlg@mk#1\bxlg@end}
\@onlypreamble\bxlg@split@name@b
\def\bxlg@split@name@b#1#2{%
  \ifx\bxlg@end#2\bxlg@end \let\bxlg@pfx\relax
  \else \def\bxlg@pfx{#1}\bxlg@split@name@c#2\bxlg@end%
  \fi}
\@onlypreamble\bxlg@split@name@c
\def\bxlg@split@name@c#1\bxlg@mk#2\bxlg@end{%
  \def\bxlg@name{#1}}

%% \bxlg@default@import
\@onlypreamble\bxlg@default@import
\def\bxlg@default@import{%
  \bxtexlogoimport{*}}
\AtBeginDocument{\bxlg@default@import}

%--------------------------------------- user interface

% NOTE: LaTeX-protection is ignored in PDF-strings,
% whereas engine-protection does not work well.

%%<*> \bxtexlogo{<name>}
\@ifdefinable\bxtexlogo{%
\DeclareRobustCommand*\bxtexlogo[1]{%
  \expandafter\bxlg@use@a\csname bxlg@lcmd@@#1\endcsname{#1}}
\def\bxlg@use@a#1#2{%
  \bxlg@cond\ifx#1\relax\fi{\bxlg@err@uknam{#2}}{#1}}
}

%%<+> \bxtexlogoTest
% The test output.
\@ifdefinable\bxtexlogoTest{%
\DeclareRobustCommand*\bxtexlogoTest{%
  \par \let\do\bxlg@logo@test@do \bxlg@list}
\def\bxlg@logo@test@do#1{%
  \texttt{#1}:\quad\@nameuse{bxlg@logo@@#1}\par}
}

%--------------------------------------- font

%% variables
\chardef\bxlg@genfam=0

%% \bxlg@find@genfam
\def\bxlg@find@genfam{%
  \edef\bxlg@tmpa{\f@family}\chardef\bxlg@genfam=\z@
  \edef\bxlg@tmpb{\sfdefault}%
  \ifx\bxlg@tmpa\bxlg@tmpb \chardef\bxlg@genfam=\@ne \fi
  \edef\bxlg@tmpb{\ttdefault}%
  \ifx\bxlg@tmpa\bxlg@tmpb \chardef\bxlg@genfam=\tw@ \fi}

%% \bxlg@check@bold
\def\bxlg@check@bold{%
  \if b\expandafter\@car\f@series.\@nil \bxlg@oktrue
  \else \bxlg@okfalse \fi}

%% \bxlg@declare@family@mw{<enc>}{<family>}
\def\bxlg@declare@family@mw#1#2{%
  \DeclareFontFamily{#1}{#2}{}%
  \DeclareFontShape{#1}{#2}{m}{it}{<->ssub*#2/m/n}{}%
  \DeclareFontShape{#1}{#2}{m}{sl}{<->ssub*#2/m/n}{}%
  \DeclareFontShape{#1}{#2}{m}{sc}{<->ssub*#2/m/n}{}%
  \DeclareFontShape{#1}{#2}{b}{it}{<->ssub*#2/b/n}{}%
  \DeclareFontShape{#1}{#2}{b}{sl}{<->ssub*#2/b/n}{}%
  \DeclareFontShape{#1}{#2}{b}{sc}{<->ssub*#2/b/n}{}%
  \DeclareFontShape{#1}{#2}{bx}{n}{<->ssub*#2/b/n}{}%
  \DeclareFontShape{#1}{#2}{bx}{it}{<->ssub*#2/bx/n}{}%
  \DeclareFontShape{#1}{#2}{bx}{sl}{<->ssub*#2/bx/n}{}%
  \DeclareFontShape{#1}{#2}{bx}{sc}{<->ssub*#2/bx/n}{}}

%% \bxlg@declare@family{<enc>}{<family>}
\def\bxlg@declare@family#1#2{%
  \bxlg@declare@family@mw{#1}{#2}%
  \DeclareFontShape{#1}{#2}{b}{n}{<->ssub*#2/m/n}{}}

%% \bxlg@use@family{<enc>}{<family>}
\def\bxlg@use@family#1#2{%
  \fontencoding{#1}\fontfamily{#2}\selectfont}

%% \bxlg@if@ipaex@ok
\IfFileExists{c70ipxg.fd}{%
  \let\bxlg@if@ipaex@ok\@firstoftwo
}{\let\bxlg@if@ipaex@ok\@secondoftwo}

%% \bxlg@declare@ipaex@family{<sub-id>}
\@onlypreamble\bxlg@declare@ipaex@family
\def\bxlg@declare@ipaex@family#1{%
  \bxlg@if@ipaex@ok{%
    \expandafter\ifx\csname U+bxlgjar#1\endcsname\relax
      \bxlg@declare@family{U}{bxlgjas#1}%
      \DeclareFontShape{U}{bxlgjas#1}{m}{n}{<->ipxg-r-u#1}{}%
      \bxlg@declare@family@mw{U}{bxlgjar#1}%
      \DeclareFontShape{U}{bxlgjar#1}{m}{n}{<->ipxm-r-u#1}{}%
      \DeclareFontShape{U}{bxlgjar#1}{b}{n}{<->ssub*bxlgjas#1/m/n}{}%
    \fi}{}}

%% \bxlg@ipaex{<sub-id>}
\def\bxlg@ipaex#1{%
  \fontencoding{U}\fontfamily{bxlgjar#1}\selectfont}

%% \bxlg@warn@font{<str>}
\def\bxlg@warn@font#1{%
  \expandafter\ifx\csname bxlg@fpkg@@#1\endcsname\relax\else
    \PackageWarning\bxlg@pkgname
     {Logo '#1' cannot be properly rendered\MessageBreak
      because the font package '\csname bxlg@fpkg@@#1\endcsname'%
      \MessageBreak is missing,}%
    \global\expandafter\let\csname bxlg@fpkg@@#1\endcsname\relax
  \fi}

%% \bxlg@required@font{<str>}{<pkg-name>}
\@onlypreamble\bxlg@required@font
\def\bxlg@required@font#1#2{%
  \@namedef{bxlg@fpkg@@#1}{#2}}

%% \bxlg@One
\bxlg@declare@family{U}{bxlgone}
\def\bxlg@next#1{\DeclareFontShape{U}{bxlgone}{m}{n}{<->#1}{}}
\IfFileExists{udsrom.fd}{%
  \bxlg@next{s*[1.44]dsrom10}%
}{\IfFileExists{ubbm.fd}{%
  \bxlg@next{s*[1.44]bbm10}%
}{\IfFileExists{ubbold.fd}{%
  \bxlg@next{s*[1.44]bbold10}%
}{%else fallback using ordinary bold
  \bxlg@next{s*[1.44]cmbx10}%
}}}
\def\bxlg@One@normal{\bxtexlogoFontSlant{%
  \usefont{U}{bxlgone}{m}{n}1}}
\let\bxlg@One\bxlg@One@normal
% bboldx version
\IfFileExists{bboldx.sty}{%
  \bxlg@declare@family@mw{U}{bxlgoneBBX}%
  \DeclareFontShape{U}{bxlgoneBBX}{m}{n}{<->s*[1.44]BBOLDX-Thin}{}%
  \DeclareFontShape{U}{bxlgoneBBX}{b}{n}{<->s*[1.44]BBOLDX-Regular}{}%
  \def\bxlg@One@BBX{\bxtexlogoFontSlant{%
    \usefont{U}{bxlgoneBBX}{\f@series}{n}1}}%
}

%%<+>\bxtexlogoUseBboldx
%%<+>\bxtexlogoNoUseBboldx
\DeclareRobustCommand*\bxtexlogoUseBboldx{%
  \let\bxlg@One\bxlg@One@BBX}
\DeclareRobustCommand*\bxtexlogoNoUseBboldx{%
  \let\bxlg@One\bxlg@One@normal}
\ifx\bxlg@One@BBX\@undefined
  \@namedef{bxtexlogoUseBboldx }{%
    \PackageError\bxlg@pkgname
     {Package 'bboldx' is not available}
     {\@eha}
    \@namedef{bxtexlogoUseBboldx }{}}
\fi

%% \bxlg@select@OTi
\def\bxlg@select@OTi{%
  \fontencoding{OT1}\selectfont
  \expandafter\ifx\csname OT1+\f@family\endcsname\@empty
    \bxlg@find@genfam
    \ifcase\bxlg@genfam \fontfamily{cmr}\selectfont
    \or \fontfamily{cmss}\selectfont
    \or \fontfamily{cmtt}\selectfont
    \fi
  \fi}

%% \bxlg@Grk{<slot>}
\def\bxlg@Grk#1{%
  \bgroup \bxlg@select@OTi \char#1\relax \egroup}

%% \bxlg@Aleph
%% \bxlg@Lamed
\IfFileExists{cjhebrew.sty}{%
  \bxlg@declare@family{U}{bxlghbr}%
  \DeclareFontShape{U}{bxlghbr}{m}{n}{<->rcjhbltx}{}%
  \def\bxlg@Aleph{%
    \bgroup \usefont{U}{bxlghbr}{m}{n}\char39\egroup}%
  \def\bxlg@Lamed{%
    \bgroup \usefont{U}{bxlghbr}{m}{n}\char108\egroup}%
}{%else
  \bxlg@required@font{logoAleph}{cjhebrew}%
  \def\bxlg@Aleph{\bxlg@warn@font{logoAleph}\textsf{Aleph}}%
  \bxlg@required@font{logoLamed}{cjhebrew}%
  \def\bxlg@Lamed{\bxlg@warn@font{logoLamed}\textsf{Lamed}}%
}

%% \bxlg@arara
\IfFileExists{comfortaa.sty}{%
  \bxlg@declare@family{U}{bxlgcomf}%
  \DeclareFontShape{U}{bxlgcomf}{m}{n}{<->Comfortaa-Bold-T1}{}%
  \def\bxlg@arara{%
    \bxlg@matchlc{0.21}{\usefont{U}{bxlgcomf}{m}{n}arara}}%
}{%else
  \bxlg@required@font{arara}{bxlgcomf}%
  \def\bxlg@arara{\bxlg@warn@font{arara}\textsf{arara}}%
}

%% \bxlg@matchlc{<coeff>}{<text>}
% NB. Here coeff is (1pt / 1ex).
\def\bxlg@matchlc#1#2{%
  \ifx\scalebox\@undefined \mbox{#2}%
  \else
    \begingroup
      \@tempdima#1ex \xdef\bxlg@@g@tmpa{\strip@pt\@tempdima}%
    \endgroup
    \scalebox{\bxlg@@g@tmpa}{#2}%
  \fi}

%% \bxlg@akern
\def\bxlg@akern#1{%
  \begingroup
    \setbox\z@\hbox{i}%
    \dimen@\wd\z@ \advance\dimen@-0.2em \dimen@12.8\dimen@
    \ifdim\dimen@<\z@ \dimen@\z@ \fi
    \ifdim\dimen@>1em \dimen@1em \fi
    \kern#1\dimen@
  \endgroup}

%% \bxlg@smaller{<text>}
\def\bxlg@smaller#1{%
  \begingroup
    \check@mathfonts
    \fontsize\sf@size\z@
    \math@fontsfalse\selectfont
    #1%
  \endgroup}

%% \bxlg@nonuc
\def\bxlg@nonuc{%
  \spacefactor\@m}

%% \bxlg@in@math{<text>}
\def\bxlg@in@math#1{%
  \begingroup
    \m@th
    \if b\expandafter\@car\f@series?\@nil \boldmath \fi
    $#1\relax$%
  \endgroup}

%--------------------------------------- slant

%% variables
\let\bxlg@slant@val\relax
\newdimen\bxlg@g@height

%%<+> \bxtexlogoFontSlant
% Uses the slant value of the current font.
%%<+> \bxtexlogoSlant{<real>}
\@ifdefinable\bxtexlogoFontSlant{%
\DeclareRobustCommand*\bxtexlogoFontSlant{%
  \begingroup
    \@tempdima\fontdimen\@ne\font
    \bxlg@slant@a}
}
\@ifdefinable\bxtexlogoSlant{%
\DeclareRobustCommand*\bxtexlogoSlant[1]{%
  \begingroup
    \@tempdima=#1\p@
    \bxlg@slant@a}
}
\def\bxlg@slant@a{%
  \bxlg@implement@slant
  \edef\bxlg@slant@val{\strip@pt\@tempdima}%
  \afterassignment\bxlg@slant@b \setbox\z@\hbox}
\def\bxlg@slant@b{%
  \aftergroup\bxlg@slant@c}
\def\bxlg@slant@c{%
    \leavevmode
    \global\bxlg@g@height\ht\z@
    \ifdim\bxlg@slant@val\p@=\z@ \box\z@
    \else
      \@tempdima\wd\z@ \wd\z@\z@
      \bxlg@slant@start \box\z@ \bxlg@slant@end
      \kern\@tempdima
    \fi
  \endgroup}

%% \bxlg@slant@start
%% \bxlg@slant@end
\def\bxlg@slant@start{%
  \PackageWarning\bxlg@pkgname
   {Cannot implement synthetic slant, perhaps\MessageBreak
    'graphics' is not loaded}%
  \global\let\bxlg@slant@start\relax}
\let\bxlg@slant@end\relax

%% \bxlg@implement@slant
\def\bxlg@implement@slant{%
  \begingroup
  \chardef\bxlg@tmpb=0
  \def\bxlg@tmpa{\special{ps: currentpoint grestore moveto}}%
  \ifx\bxlg@tmpa\Grot@end \chardef\bxlg@tmpb=1 \fi
  \def\bxlg@tmpa{\special{pdf:etrans}}%
  \ifx\bxlg@tmpa\Grot@end \chardef\bxlg@tmpb=2 \fi
  \def\bxlg@tmpa{\pdfrestore}%
  \ifx\bxlg@tmpa\Grot@end \chardef\bxlg@tmpb=3 \fi
  \def\bxlg@tmpa{\pdfextension restore\relax}%
  \ifx\bxlg@tmpa\Grot@end \chardef\bxlg@tmpb=4 \fi
  \def\bxlg@tmpa{dvipdfmx.def}%
  \ifx\bxlg@tmpa\Gin@driver \chardef\bxlg@tmpb=2 \fi
  \def\bxlg@tmpa{xetex.def}%
  \ifx\bxlg@tmpa\Gin@driver \chardef\bxlg@tmpb=2 \fi
  \bxDebug{[gdriver=\the\bxlg@tmpb]}%
  \ifcase\bxlg@tmpb
    % unknown, then leave unimplmented
  \or % dvips
    % TODO: implement
  \or % dvipdfmx
    \gdef\bxlg@slant@start{\special{%
      pdf:btrans matrix 1 0 \bxlg@slant@val\space 1 0 0}}
    \gdef\bxlg@slant@end{\special{pdf:etrans}}
  \or % pdftex
    \gdef\bxlg@slant@start{%
      \pdfsave \pdfsetmatrix{1 0 \bxlg@slant@val\space 1}}
    \gdef\bxlg@slant@end{\pdfrestore}
  \or % luatex (new)
    \gdef\bxlg@slant@start{%
      \pdfextension save\relax
      \pdfextension setmatrix{1 0 \bxlg@slant@val\space 1}}
    \gdef\bxlg@slant@end{\pdfextension restore\relax}
  \fi
  \global\let\bxlg@implement@slant\relax
  \endgroup}
\AtBeginDocument{\bxlg@implement@slant}

%% \bxlg@fallback@slant
\def\bxlg@fallback@slant{0.167}

%%<+> \bxtexlogoItalicOrSlant
% Uses the slant value of the current font.
\@ifdefinable\bxtexlogoItalicOrSlant{%
\DeclareRobustCommand*\bxtexlogoItalicOrSlant[1]{%
  \textit{%
    \@tempdima\fontdimen\@ne\font
    \ifdim\@tempdima>\z@
      #1%
    \else
      \bxtexlogoSlant\bxlg@fallback@slant{#1}%
      \@tempdima\bxlg@fallback@slant\bxlg@g@height
      \kern.75\@tempdima
    \fi}}
}

%--------------------------------------- reflect

%%<+> \bxtexlogoReflect{<text>}{<fallback>}
\@ifdefinable\bxtexlogoReflect{%
\DeclareRobustCommand*\bxtexlogoReflect{%
  \bxlg@cond\ifx\reflectbox\@undefined\fi
    {\bxlg@reflect@b}{\bxlg@reflect@a}}
\def\bxlg@reflect@a#1#2{\reflectbox{\upshape#1}}
\def\bxlg@reflect@b{%
  \PackageWarning\bxlg@pkgname
   {Package 'graphics' is not loaded,\MessageBreak reported}%
  \global\let\bxlg@reflect@b\@secondoftwo
  \@secondoftwo}
}

%--------------------------------------- small-caps

%% constants
\chardef\bxlg@smcp@@auto=0
\chardef\bxlg@smcp@@real=1
\chardef\bxlg@smcp@@fake=2

%% variables
\let\bxlg@use@fake@list\@empty
\let\bxlg@smcp@mode\bxlg@smcp@@auto

%%<+> \bxtexlogoSmcp{<string>}
\@ifdefinable\bxtexlogoSmcp{%
\DeclareRobustCommand\bxtexlogoSmcp[1]{%
  \bxtexlogoSmcpChoice{\MakeLowercase{#1}}{\MakeUppercase{#1}}}
}

%%<+> \bxtexlogoSmcpChoice{<text1>}{<text2>}
\@ifdefinable\bxtexlogoSmcpChoice{%
\DeclareRobustCommand\bxtexlogoSmcpChoice[2]{%
  \begingroup
    \bxlg@check@smcp
    \ifbxlg@ok \scshape #1%
    \else \bxlg@smaller{#2}%
    \fi
  \endgroup}
}

%%<+> \bxtexlogoSmcpAs{<value>}
% valus: auto, real, fake
\@ifdefinable\bxtexlogoSmcpAs{%
\DeclareRobustCommand*\bxtexlogoSmcpAs[1]{%
  \expandafter\let\expandafter\bxlg@tmpa\csname bxlg@smcp@@#1\endcsname
  \ifx\bxlg@tmpa\relax
    \bxlg@err@ukval{#1}%
  \else \let\bxlg@smcp@mode\bxlg@tmpa
  \fi}
}

%%<+> \bxtexlogoSmcpAsFakeFor
\@ifdefinable\bxtexlogoSmcpAsFakeFor{%
\DeclareRobustCommand*\bxtexlogoSmcpAsFakeFor[1]{%
  \edef\bxlg@use@fake@list{\bxlg@use@fake@list,#1}}
}

%% \bxlg@check@smcp
\def\bxlg@check@smcp{%
  \ifx\bxlg@smcp@mode\bxlg@smcp@@real
    \bxlg@oktrue
  \else\ifx\bxlg@smcp@mode\bxlg@smcp@@fake
    \bxlg@okfalse
  \else
    \bxlg@check@smcp@manual
    \ifbxlg@ok \bxlg@check@smcp@auto \fi
  \fi\fi
  \bxDebug{[check->\meaning\ifbxlg@ok]}}
\def\bxlg@check@smcp@manual{%
  \bxlg@oktrue
  \begingroup
    \@for\bxlg@tmpb:=\bxlg@use@fake@list\do{%
      \expandafter\bxlg@check@smcp@manual@a\bxlg@tmpb/?/?/?\bxlg@end}%
  \endgroup
  \bxDebug{[manual->\meaning\ifbxlg@ok]}}
\def\bxlg@check@smcp@manual@a#1/#2/#3/#4\bxlg@end{%
  \bxlg@check@smcp@manual@b{#1}{\f@encoding}%
  \if@tempswa\else \bxlg@jump@exit \fi
  \bxlg@check@smcp@manual@b{#2}{\f@family}%
  \if@tempswa\else \bxlg@jump@exit \fi
  \bxlg@check@smcp@manual@b{#3}{\f@series}%
  \if@tempswa\else \bxlg@jump@exit \fi
  \aftergroup\bxlg@okfalse
  \bxlg@exit}
\def\bxlg@check@smcp@manual@b#1#2{%
  \def\bxlg@tmpa{#1}%
  \@tempswafalse
  \ifx\bxlg@@star\bxlg@tmpa \@tempswatrue
  \else\ifx#2\bxlg@tmpa \@tempswatrue
  \fi\fi}
\def\bxlg@check@smcp@auto{%
  \bxlg@oktrue
  \begingroup
    \bxlg@setcurfont\bxlg@fn@orig
    \edef\bxlg@sl@orig{\ifdim\fontdimen1\font>\z@ 1\else 0\fi}%
    \scshape
    \bxlg@setcurfont\bxlg@fn@smcp
    \edef\bxlg@sl@smcp{\ifdim\fontdimen1\font>\z@ 1\else 0\fi}%
    \ifx\bxlg@fn@orig\bxlg@fn@smcp
      \aftergroup\bxlg@okfalse
    \else\ifnum\bxlg@sl@orig=\bxlg@sl@smcp\else
      \aftergroup\bxlg@okfalse
    \fi\fi
  \endgroup
  \bxDebug{[auto->\meaning\ifbxlg@ok]}}

%% \bxlg@setcurfont\CS
\def\bxlg@setcurfont#1{%
  \edef\bxlg@tempa{\expandafter\meaning\the\font}%
  \expandafter\bxlg@setcurfont@a\bxlg@tempa\bxlg@mk#1}
\def\bxlg@setcurfont@a#1 #2 #3\bxlg@mk#4{\def#4{#3}}

%% initial setup
\bxtexlogoSmcpAs{auto}
\bxtexlogoSmcpAsFakeFor{*/cmss/*,*/lmss/*}

%--------------------------------------- components

%% \bxlg@epsilon
\def\bxlg@epsilon{%
  \bxlg@in@math{\varepsilon}}

%% \bxlg@cal{<arg>}
\def\bxlg@cal#1{%
  \bxlg@in@math{\mathcal{#1}}}

%% \bxlg@Suyah
%% \bxlg@Yukidaruma
\bxlg@if@ipaex@ok{%
  \bxlg@declare@ipaex@family{ff}%
  \def\bxlg@syt{\kern-0.06em}%
  \def\bxlg@Suyah{\bxtexlogoFontSlant{%
    \bxlg@ipaex{ff}\bfseries%
    \char125\bxlg@syt\char148\bxlg@syt\char103 }}%
  \bxlg@declare@ipaex@family{26}%
  \def\bxlg@Yukidaruma{\bxtexlogoFontSlant{%
    \bxlg@ipaex{26}\char3 }}%
}{%else
  \bxlg@required@font{SuyahTeX}{ipaex-type1}%
  \def\bxlg@Suyah{\bxlg@warn@font{SuyahTeX}%
    \textsf{Suyah}}%
  \bxlg@required@font{YukidarumaTeX}{ipaex-type1}%
  \def\bxlg@Yukidaruma{\bxlg@warn@font{YukidarumaTeX}%
    \textsf{Yukidaruma}}%
}

%--------------------------------------- done
\endinput
