% TeX Live documentation style. Written by many people over many years.
% Edited by Takuto Asakura for Japanese version.
% Public domain.
\NeedsTeXFormat{pLaTeX2e}[2018/03/09]
\ProvidesPackage{texlive-ja}[2019/09/24 Japanese TeX Live Guide style]

% ------------------------------------------------------------- Packages

\RequirePackage[T1]{fontenc}
\RequirePackage{alltt}
\RequirePackage{array}
\RequirePackage{colortbl}
\RequirePackage{comment}
\RequirePackage{float}
\RequirePackage{graphicx}
\RequirePackage{longtable}
\RequirePackage{enumitem}
\RequirePackage[normalem]{ulem}
\RequirePackage[obeyspaces]{url}
\RequirePackage{textcomp}% including \textbullet
\RequirePackage{fancyvrb}
\RequirePackage[verb]{bxghost}
\RequirePackage{pxrubrica}
\RequirePackage{hyperref}

% ------------------------------------------------------------- LaTeX style

\pagestyle{headings}

\renewcommand{\topfraction}{0.85}
\renewcommand{\floatpagefraction}{0.86}
\renewcommand{\textfraction}{0.1}
\renewcommand{\abovecaptionskip}{4pt}
\renewcommand{\belowcaptionskip}{4pt}

\setcounter{tocdepth}{3}
\setcounter{secnumdepth}{3}
\setcounter{topnumber}{5}
\setcounter{totalnumber}{5}

% linebreaking, etc.
\hbadness=4000
\vbadness=4000
\emergencystretch=.1\hsize
\relpenalty=500

% font
\DeclareTextFontCommand{\emph}{\sffamily\gtfamily}

% ------------------------------------------------------------- Markup commands

\def\p.{p.\,}
\renewcommand*{\slash}{/\penalty\z@\hskip\z@skip }

% various sorts of names
\newcommand*{\pkg}[1]{\eghostguarded{{\chardef\_=`\_\textsf{#1}}}}
\newcommand*{\prog}[1]{\eghostguarded{\textsf{#1}}}
\newcommand*{\dir}[1]{\path{#1}}% \eghostguarded is unnecessary for \path
\newcommand*{\file}[1]{\path{#1}}
\newcommand*{\cmd}[1]{\eghostguarded{\texttt{#1}}}
\newcommand*{\code}[1]{\eghostguarded{\texttt{#1}}}
\newcommand*{\sopt}[1]{\code{\hyph#1}}
\newcommand*{\lopt}[1]{\code{\hyph{}\hyph#1}}
\newcommand*{\var}[1]{{\chardef\_=`\_\code{#1}}}
\newcommand*{\meta}[1]{$\langle$\mbox{}{\normalfont #1}\mbox{}$\rangle$}
\newcommand*{\optional}[1]{\textrm{[\code{#1}]}}
\newcommand*{\samp}[1]{`\texttt{#1}'\@}

% Windows-specific
\newcommand*{\winenv}[1]{\code{\%#1\%}}
\newcommand*{\winpath}[1]{{\def\\{\char`\\}\code{#1}}}

% special names
\newcommand*{\dpi}{$\,$dpi}
\newcommand*{\bs}{\char`\\}
\newcommand*{\cs}[1]{\eghostguarded{\texttt{\bs #1}}}
\newcommand*{\Q}[1]{\par\vskip6pt\leftline{#1}\par}
\newcommand*{\hyph}{-}

% abbreviations
\newcommand*{\KPS}{Kpathsea}
\newcommand*{\PS}{Post\-Script}
\newcommand*{\WEB}{\texttt{WEB}}
\newcommand*{\Webc}{Web2C}

% ------------------------------------------------------------- TeX logos

\RequirePackage{bxtexlogo}% use instead of texnames
\bxtexlogoimport{*,HanTheThanh,PiCTeX,LaTeXTeX,%
  logoOmega,logoLambda,logoLamed,logoAleph}

% aliases
\let\MF\METAFONT
\let\MP\METAPOST
\let\AllTeX\LaTeXTeX
\let\Thanh\HanTheThanh
\newcommand{\OMEGA}{\eghostguarded{\logoOmega}}
\newcommand{\LAMBDA}{\eghostguarded{\logoLambda}}
\newcommand{\LAMED}{\eghostguarded{\logoLamed}}
\newcommand{\ALEPH}{\eghostguarded{\logoAleph}}

% logos not in bxtexlogo
\DeclareRobustCommand{\TL}{\texorpdfstring{\TeX\,\,Live}{TeX Live}}
\DeclareRobustCommand{\TeXXeT}{\TeX-{}-%
  \kern-.1emX\kern-.125em\lower.5ex\hbox{E}\kern-.1667emT\@}
\DeclareRobustCommand{\MIKTEX}{MiK\kern-.025em \TeX}% per www.miktex.org
\DeclareRobustCommand{\ProTeXt}{pro\TeX t}
\DeclareRobustCommand{\teTeX}{\textrm{te}\TeX}
\DeclareRobustCommand{\MacTeX}{Mac\TeX}

% ------------------------------------------------------------- Verbatim

\DefineVerbatimEnvironment{verbatim}{Verbatim}{fontsize=\normalsize}
\DefineVerbatimEnvironment{fverbatim}{Verbatim}{fontsize=\footnotesize}
\DefineVerbatimEnvironment{sverbatim}{Verbatim}{fontsize=\small}
\DefineVerbatimEnvironment{boxedverbatim}
  {Verbatim}{fontsize=\footnotesize,frame=single}
\DefineVerbatimEnvironment{Verbatim}{Verbatim}{fontsize=\normalsize}
\def\verbatiminput#1{\VerbatimInput[fontsize=\scriptsize]{#1}}
\def\boxedverbatiminput#1{\VerbatimInput[frame=single,fontsize=\scriptsize]{#1}}
\def\listinginput#1#2{\VerbatimInput[fontsize=\scriptsize,firstnumber=#1,numbers=left]{#2}}
%\MakeShortVerb\|

% ------------------------------------------------------------- Graphics

% graphics path
\graphicspath{{texlive-common/}{img/}}

\def\tlpng#1#2{%
  \par
  \centerline{\includegraphics[width=#2]{#1.png}}%
}

% ------------------------------------------------------------- Lists

% description-like environment that uses tt instead of bf, and doesn't
% go to the left margin.  Without the \hfil, get an underfull box.
% Don't know why \descriptionlabel doesn't.
\newenvironment{ttdescription}{%
  \list{label must be supplied}{%
    \parindent=0pt
    \itemsep=0pt  % these lists tend to have short descriptions
    \labelwidth=\leftmargin
    \labelsep=1zw
    \advance\labelwidth by -\labelsep
    \let\makelabel=\ttdescriptionlabel}}{\endlist}
\newcommand*\ttdescriptionlabel[1]{%
  %\hspace\labelsep
  \normalfont\ttfamily #1\hfil}

% Likewise, for commands using sans serif.
\newenvironment{cmddescription}{%
  \list{label must be supplied}{%
    \itemsep=0pt
    \labelwidth=\leftmargin
    \labelsep=1zw
    \advance\labelwidth by -\labelsep
    \let\makelabel=\cmddescriptionlabel}}{\endlist}
\newcommand*\cmddescriptionlabel[1]{%
  %\hspace\labelsep
  \normalfont\sffamily #1\hfil}

\newsavebox{\wbox}
\newenvironment{warningbox}
 {\begin{lrbox}{\wbox}
 \begin{minipage}{.95\textwidth}}
 {\end{minipage}\end{lrbox}\fbox{\usebox{\wbox}}}
%
% lrbox is used as a representation marking. I changed it to
% lrBox in tne source file, to get closer to logical marking
\newsavebox{\mylrbox}
\newenvironment{lrBox}
 {\begin{lrbox}{\mylrbox}}
 {\end{lrbox}}

% ------------------------------------------------------------- Boxes

\RequirePackage{tcolorbox}
\tcbuselibrary{skins,breakable}

\newtcolorbox{janote}
  {
    empty, left=2mm, right=2mm, top=-1mm,
    attach boxed title to top left={xshift=1.2zw},
    boxed title style={
      empty, left=-1mm, right=-1mm,
    },
    colframe=black, coltitle=black, coltext=black, breakable,
    underlay unbroken={
      \draw [black, line width=.5pt]
        (title.east) -- (title.east-|frame.east) -- (frame.south east)
          -- (frame.south west) -- (title.west-|frame.west) -- (title.west);
    },
    underlay first={
      \draw [black, line width=.5pt] (title.east) -- (title.east-|frame.east)
        -- (frame.south east);
      \draw [black, line width=.5pt] (frame.south west)
        -- (title.west-|frame.west) -- (title.west);
    },
    underlay middle={
      \draw [black, line width=.5pt]
        (frame.north east) -- (frame.south east) ;
      \draw [black, line width=.5pt] (frame.south west) -- (frame.north west) ;
    },
    underlay last={
      \draw [black, line width=.5pt] (frame.north east) -- (frame.south east)
        -- (frame.south west) -- (frame.north west) ;
    },
    fonttitle=\sffamily\gtfamily,
    title={日本語\TeX ユーザ向けノート},
  }

% ------------------------------------------------------------- LaTeX hacks

% Japanese translaion supports only PDF (HTML version is not available)
\typeout{TeX Live documentation in PDF format}

% title
\def\Title#1{\gdef\@title{{\huge #1}}}
\def\Editor#1{\gdef\@editor{#1}}
\def\Translator#1{\gdef\@translator{#1}}
\def\Website#1{\gdef\@website{\url{#1}}}
\author{%
  {\@editor} 編 \\
  {\@translator} 訳 \\[3mm]
  \@website}

% hyperref settings
\newcommand*{\email}[1]{\href{mailto:#1}{\path{#1}}}  % \path comes from url
\definecolor{hypercolor}{rgb}{0.5,0.0,0.5} % purplish external links.
\hypersetup{
  breaklinks, colorlinks, linkcolor=hypercolor, citecolor=hypercolor,
  urlcolor=hypercolor, filecolor=hypercolor, bookmarksopen, hyperindex
}

\AtBeginDocument{%
  \hypersetup{
    pdftitle = {\@title},
    pdfauthor = {\@editor，\@translator，ほか},
  }
}

% array package stuff
\def\arraybackslash{\let\\=\@arraycr}
\newcolumntype{P}[1]{>{\raggedright\arraybackslash}p{#1}}

% shaded rows (using facilities of colortbl)
\definecolor{pale}{gray}{.9}
\newcount\colrow
\gdef\RowColor{pale}
\def\SetRowColor{%
 \rowcolor{\RowColor}%
 \global\advance\colrow by1\relax
 \ifodd\colrow
   \gdef\RowColor{pale}%
 \else
   \gdef\RowColor{white}%
 \fi
}

% redefine to hack up a reference even though we don't need it...
\renewcommand\@bibitem[1]{\if@filesw \immediate\write\@auxout
  {\string\bibcite{#1}{?}}\fi\ignorespaces}

% \unknownTeXlive is a dummy texlive entry for the biblio
\newcommand\unknownTeXlive[2][\relax]{\textbf{\textsc{unknown}}%
  \global\@all@unknown\expandafter{\the\@all@unknown{#2}}%
}
\newtoks\@all@unknown
\global\@all@unknown{}
\AtEndDocument{\@message@unknowns}
\def\@message@unknowns{\edef\@tempa{\the\@all@unknown}%
  \ifx\@tempa\@empty
  \else
    \def\@tempa{*** TeX Live package location of }%
    \expandafter\@output@unknowns\the\@all@unknown\@empty
  \fi
}
\def\@output@unknowns#1{\edef\@tempb{#1}%
  \ifx\@tempb\@empty
    \typeout{ unknown}%
  \else
    \message{\@tempa#1,}%
    \def\@tempa{}%
    \expandafter\@output@unknowns
  \fi
}

% Silence font warnings about no bold typewriter in LM.
\def\@font@warning#1{}%

% Silence hyperref warnings about \kern.
\def\HyPsd@Warning#1{}%

\endinput
