%% file `cleveref-korean.sty`
%%
%% (C) Copyright 2024 강우현 <kangwh.2003 at gmail.com>
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3c
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%  http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2006/05/20 or later.
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{cleveref-korean}[2024/03/31 Korean localisation of cleveref package]

\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{cleveref}}
\ProcessOptions\relax
\RequirePackage{cleveref}

\newcommand\crefrangeconjunction{\~{}}
\newcommand\crefpairconjunction{\와\space}
\newcommand\crefmiddleconjunction{, }
\newcommand\creflastconjunction{, }
\newcommand\crefpairgroupconjunction{\와\space}
\newcommand\crefmiddlegroupconjunction{, }
\newcommand\creflastgroupconjunction{, 그리고 }

\crefname{part}{편}{편}
\crefname{chapter}{장}{장}
\crefname{section}{절}{절}
\crefname{appendix}{부록}{부록}
\crefname{table}{표}{표}
\crefname{figure}{그림}{그림}
\crefname{equation}{식}{식}
\crefname{footnote}{각주}{각주}
\crefname{page}{쪽}{쪽}

\crefformat{part}{제#2#1#3편}
\crefformat{chapter}{제#2#1#3장}
\crefformat{section}{#2#1#3절}
\crefformat{page}{#2#1#3쪽}

\crefrangeformat{part}{제#3#1#4\~{}#5#2#6편}
\crefrangeformat{chapter}{제#3#1#4\~{}#5#2#6장}
\crefrangeformat{section}{#3#1#4\~{}#5#2#6절}
\crefrangeformat{page}{#3#1#4\~{}#5#2#6쪽}

\crefmultiformat{part}{제#2#1#3}{편과 제#2#1#3편}{, #2#1#3}{, #2#1#3편}
\crefmultiformat{chapter}{제#2#1#3}{장과 제#2#1#3장}{, #2#1#3}{, #2#1#3장}
\crefmultiformat{section}{#2#1#3}{절과 #2#1#3절}{, #2#1#3}{, #2#1#3절}
\crefmultiformat{page}{#2#1#3}{쪽과 #2#1#3쪽}{, #2#1#3}{, #2#1#3쪽}

\crefrangemultiformat{part}{제#3#1#4\~{}#5#2#6}
  {편과 제#3#1#4\~{}#5#2#6편}{, #3#1#4\~{}#5#2#6}{, #3#1#4\~{}#5#2#6편}
\crefrangemultiformat{chapter}{제#3#1#4\~{}#5#2#6}
  {장과 제#3#1#4\~{}#5#2#6장}{, #3#1#4\~{}#5#2#6}{, #3#1#4\~{}#5#2#6장}
\crefrangemultiformat{section}{#3#1#4\~{}#5#2#6}
  {절과 #3#1#4\~{}#5#2#6절}{, #3#1#4\~{}#5#2#6}{, #3#1#4\~{}#5#2#6절}
\crefrangemultiformat{page}{#3#1#4\~{}#5#2#6}
  {쪽과 #3#1#4\~{}#5#2#6쪽}{, #3#1#4\~{}#5#2#6}{, #3#1#4\~{}#5#2#6쪽}

\@ifpackageloaded{varioref}{%
  \newif\ifkcr@faraway \kcr@farawayfalse
  \def\reftextfaraway#1{\pageref{#1}쪽\kvr@ui\global\kcr@farawaytrue}
  \def\reftextpagerange#1#2{\pageref{#1}\~{}\pageref{#2}쪽\kvr@eitneun\global\kcr@farawaytrue}

  \def\cref@vref#1#2{%
    \leavevmode%
    \begingroup%
      \def\reftextcurrent{}%
      \begingroup\UIfalse%
      \cref@@vpageref{\reftextcurrent}[]{#2}\endgroup%
      \ifkcr@faraway\kvr@eitneun\fi\global\kcr@farawayfalse%
      \@setcref@space\@cref{#1}{#2}%
    \endgroup}%
  \def\cref@vrefrange#1#2#3{%
    \vpagerefrange{#2}{#3}\@setcref@space%
    \@@setcrefrange{#1}{#2}{#3}{}}%
  \def\cref@fullref#1#2{%
    \begingroup\UIfalse\@cref{fullpageref}{#2}\endgroup%
    \kvr@eitneun\@setcref@space\@cref{#1}{#2}}%
}

\endinput