%%
%% This is file `sjtu-thesis-preset-base.def',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% sjtutex.dtx  (with options: `preset,thesis')
%% 
%%     Copyright (C) SJTUG
%%       2018--2026 Weijian Wu   <alexarawu@outlook.com>
%%       2022--2026 Zilong Li    <logcreative@outlook.com>
%%       2024--2026 Boshi Yuan   <nemoyuan2008@outlook.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
%%       https://www.latex-project.org/lppl.txt
%%     and version 1.3c or later is part of all distributions of LaTeX
%%     version 2008 or later.
%% 
\GetIdInfo$Id: sjtutex.dtx 19925b2 2026-02-26 23:13:21 +0800 Alexara Wu <alexarawu@outlook.com> $
  {Thesis document preset for Shanghai Jiao Tong University (SJTUTeX)}
\ProvidesExplFile{sjtu-thesis-preset-base.def}
  {\ExplFileDate}{2.3.1}{\ExplFileDescription}
\cs_new_protected:Npn \__sjtu_info_keys_define:n #1
  {
    \clist_map_inline:nn
      { title, display_title, subject }
      { \tl_new:c { l__sjtu_info_ ##1 _ #1 _tl } }
    \clist_map_inline:nn
      { keywords, fund }
      { \clist_new:c { l__sjtu_info_ ##1 _ #1 _clist } }
    \bool_if:NTF \g__sjtu_review_bool
      {
        \seq_set_from_clist:cn { l__sjtu_info_show_ #1 _seq }
          { author, id, supervisor, department, major, degree }
      }
      { \seq_new:c { l__sjtu_info_show_ #1 _seq } }
    \keys_define:nn { sjtu }
      { info / #1 .meta:nn = { sjtu / info / #1 } {##1} }
    \keys_define:nn { sjtu / info }
      {        #1 .meta:nn = { sjtu / info / #1 } {##1} }
    \keys_define:nn { sjtu / info / #1 }
      {
        display-title       .code:n =
          {
            \tl_set:co { l__sjtu_info_display_title_ #1 _tl }
              { \cs:w __sjtu_title_case_aux_ #1 :n \cs_end: {##1} }
          } ,
        title               .code:n =
          {
            \tl_set:cn { l__sjtu_info_title_ #1 _tl } {##1}
            \tl_if_empty:cT { l__sjtu_info_display_title_ #1 _tl }
              { \keys_set:nn { sjtu / info / #1 } { display-title = {##1} } }
          } ,
        subject           .tl_set:c = { l__sjtu_info_subject_ #1 _tl } ,
        subject          .initial:o = { \cs:w c__sjtu_name_subject_ #1 _tl \cs_end: } ,
        keywords       .clist_set:c = { l__sjtu_info_keywords_ #1 _clist } ,
        fund           .clist_set:c = { l__sjtu_info_fund_ #1 _clist } ,
        fund              .groups:n = { sensitive } ,
        date               .meta:nn = { sjtu / info } { date = {##1} } ,
        display-date      .tl_set:c = { l__sjtu_info_date_ #1 _tl } ,
        @show+              .code:n =
          {
            \seq_if_in:cnF { l__sjtu_info_show_ #1 _seq } {##1}
              { \seq_put_right:cn { l__sjtu_info_show_ #1 _seq } {##1} }
          } ,
        @show+            .groups:n = { sensitive }
      }
  }
\clist_const:Nn \c__sjtu_info_entries_zh_clist
  {
    author*           = { 姓名              } ,
    id*               = { 学号              } ,
    supervisor*       = { 导师              } ,
    assoc-supervisor* = { 副导师            } ,
    co-supervisor*    = { 联合导师          } ,
    department        = { 院系              } ,
    major             = { 学科 \, / \, 专业 } ,
    degree            = { 申请学位          }
  }
\clist_const:Nn \c__sjtu_info_entries_en_clist
  {
    author*           = { Author             } ,
    supervisor*       = { Supervisor         } ,
    assoc-supervisor* = { Assoc.\ Supervisor } ,
    co-supervisor*    = { Co-supervisor      } ,
    department , major , degree
  }
\clist_const:Nn \c__sjtu_info_entries_de_clist
  {
    author*           = { Autor/in         } ,
    supervisor*       = { Betreuer/in      } ,
    assoc-supervisor* = { Zweitbetreuer/in } ,
    co-supervisor*    = { Co-Betreuer/in   } ,
    department , major , degree
  }
\clist_const:Nn \c__sjtu_info_entries_ja_clist
  {
    author*           = { 氏名       } ,
    supervisor*       = { 指導教員   } ,
    assoc-supervisor* = { 副指導教員 } ,
    co-supervisor*    = { 共同指導   } ,
    department , major , degree
  }
\clist_map_inline:Nn \g__sjtu_lang_clist
  {
    \__sjtu_info_keys_define:n {#1}
    \exp_args:Nnv \SetInfoEntry { #1 }
      { c__sjtu_info_entries_ #1 _clist }
  }
\keys_define:nn { sjtu / info }
  {
    id   .meta:n = { zh / id = {#1} } ,
    id .groups:n = { sensitive }
  }
\tl_set:Nn \l__sjtu_header_tl { \songti \l__sjtu_info_subject_zh_tl }
\tl_set:Nn \@title  { \l__sjtu_info_title_zh_tl }
\tl_set:Nn \@author { \l__sjtu_info_author_zh_tl }
\keys_define:nn { sjtu / info }
  {
    date .code:n =
      {
        \clist_map_inline:Nn \g__sjtu_lang_clist
          { \__sjtu_date_set:cnn { l__sjtu_info_date_ ##1 _tl } {##1} {#1} }

      } ,
    date .initial:V = \c__sjtu_date_tl
  }
\tl_set:Nn \SJTU@CT@W@width { 5 em }
\newcolumntype { \SJTU@CT@W } [ 1 ]
  {
    w {#1} { \SJTU@CT@W@width }
    @{ \tl_use:c { c__sjtu_name_info_sep_ \l__sjtu_lang_tl _tl } }
  }
\newcolumntype { \SJTU@CT@R }
  { r @{ \tl_use:c { c__sjtu_name_info_sep_ \l__sjtu_lang_tl _tl } } }
\newcolumntype { \SJTU@CT@L }
  { >{ \linespread { 0.75 } \normalfont } l }
\cs_new:Npn \ps@SJTU@fund
  {
    \ps@empty
    \tl_set:Nn \@oddfoot
      {
        \hfil
        \minipage [ t ] { \textwidth }
          \centering \zihao { - 5 }
          \clist_use:cn { l__sjtu_info_fund_ \l__sjtu_lang_tl _clist } { \par }
        \endminipage
        \hfil
      }
    \tl_set_eq:NN \@evenfoot \@oddfoot
  }
\clist_map_inline:nn
  {
    { logo    }
      {
        content     =
          {
            \includegraphics [ width = 3 cm ]
              { sjtu-vi-badge-reg-red.pdf }
          }
      } ,
    { subject }
      {
        format      = \zihao { -2 } \setbaselineskip { 30 bp } ,
        content     = \tl_use:c { l__sjtu_info_subject_ \l__sjtu_lang_tl _tl } ,
        bottom-skip = \c_zero_dim plus 1 fill
      } ,
    { title   }
      {
        format      = \zihao { 2 } \setbaselineskip { 36 bp } \bfseries ,
        content     = \tl_use:c { l__sjtu_info_display_title_ \l__sjtu_lang_tl _tl } ,
        bottom-skip = 30 bp plus 1 fill
      } ,
    { info    }
      {
        format      = \zihao { 4 } \setbaselineskip { 30 bp } \heiti ,
        content     = \__sjtu_title_page_info_table:n
                        { \SJTU@CT@W { s } \SJTU@CT@L } ,
        bottom-skip = 30 bp
      } ,
    { date    }
      {
        format      = \zihao { 4 } \setbaselineskip { 30 bp } \bfseries ,
        content     = \tl_use:c { l__sjtu_info_date_ \l__sjtu_lang_tl _tl } ,
      }
  }
  { \__sjtu_declare_element_instance:nnn { title a } #1 }
\__sjtu_declare_page_instance:nnn { title a }
  {
    bookmark = \tl_use:c { c__sjtu_name_title_page_ \g__sjtu_lang_tl _tl } ,
    style    = SJTU@fund ,
    prefix   = title a ,
    elements = { logo, subject, title, info, date }
  }
\clist_map_inline:nn
  {
    { subject }
      {
        format      = \zihao { 4 } \setbaselineskip { 24 bp } \bfseries ,
        content     = \tl_use:c { l__sjtu_info_subject_ \l__sjtu_lang_tl _tl } ,
        bottom-skip = \c_zero_dim plus 1 fill
      } ,
    { title   }
      {
        format      = \zihao { -2 } \setbaselineskip { 30 bp } \bfseries ,
        content     = \tl_use:c { l__sjtu_info_display_title_ \l__sjtu_lang_tl _tl } ,
        bottom-skip = \c_zero_dim plus 1 fill
      } ,
    { info    }
      {
        format      = \zihao { 3 } \setbaselineskip { 30 bp } \bfseries ,
        content     = \__sjtu_title_page_info_table:n
                        { \SJTU@CT@R \SJTU@CT@L } ,
        bottom-skip = 30 bp plus 1 fill
      } ,
    { date    }
      {
        format      = \zihao { 3 } \setbaselineskip { 30 bp } ,
        content     =
          {
            \tl_use:c { l__sjtu_info_department_ \l__sjtu_lang_tl _tl }
            \skip_vertical:N \c_zero_skip
            \tl_use:c { c__sjtu_name_univ_ \l__sjtu_lang_tl _tl }
            \skip_vertical:N \c_zero_skip
            \tl_use:c { c__sjtu_name_address_ \l__sjtu_lang_tl _tl }
            \skip_vertical:N \c_zero_skip
            \tl_use:c { l__sjtu_info_date_ \l__sjtu_lang_tl _tl }
          }
      }
  }
  { \__sjtu_declare_element_instance:nnn { title b } #1 }
\__sjtu_declare_page_instance:nnn { title b }
  {
    prefix   = title b ,
    style    = SJTU@fund ,
    elements = { subject, title, info, date }
  }
\prop_const_from_keyval:Nn \c__sjtu_title_page_style_prop
  {
    zh = { title a } ,
    en = { title b } ,
    de = { title b } ,
    ja = { title b }
  }
\clist_map_inline:Nn \g__sjtu_lang_clist
  {
    \prop_get:NnN \c__sjtu_title_page_style_prop {#1} \l__sjtu_tmp_tl
    \DeclareInstanceCopy { sjtu / page } { title / #1 } { \l__sjtu_tmp_tl }
  }
\RenewDocumentCommand \maketitle { }
  {
    \clist_map_inline:Nn \g__sjtu_lang_clist
      { \UseInstance { sjtu / page } { title / ##1 } { ##1 } }
  }
\tl_const:Nn \c__sjtu_orig_decl_text_a_zh_tl
  {
    本人郑重声明：所呈交的学位论文，是本人在导师的指导下，独立进行研究工
    作所取得的成果。
    除文中已经注明引用的内容外，本论文不包含任何其他个人或集体已经发表或
    撰写过的作品成果。
    对本文的研究做出重要贡献的个人和集体，均已在文中以明确方式标明。
    本人完全知晓本声明的法律后果由本人承担。
  }
\tl_const:Nn \c__sjtu_orig_decl_text_b_zh_tl
  {
    本人郑重声明：所呈交的学位论文，是本人在导师的指导下，独立进行研究工
    作所取得的成果。
    除文中已经注明引用的内容外，本论文不包含任何其他个人或集体已经发表或
    撰写过的作品成果。
    对本文的研究做出重要贡献的个人和集体，已在文中以适当方式予以致谢。
    若在论文撰写过程中使用了人工智能工具，本人已遵循《上海交通大学关于在
    教育教学中使用~ AI~ 的规范》，确保人工智能生成内容的应用场景、引用范
    围及标注方式均符合规定，并杜绝学术不端行为。
    本人完全知晓本声明的法律后果由本人承担。
  }
\tl_const:Nn \c__sjtu_auth_decl_text_zh_tl
  {
    本人同意学校保留并向国家有关部门或机构送交论文的复印件和电子版，允许
    论文被查阅和借阅。 \par
    \vskip 6 bp
    \noindent
    本学位论文属于： \par
    { \c__sjtu_symbol_white_square_tl } \, \textbf { 公开论文 } \par
    { \c__sjtu_symbol_white_square_tl } \, \textbf { 内部论文 }，
      保密 \, { \c__sjtu_symbol_white_square_tl } \, 1 \, 年 \, /
           \, { \c__sjtu_symbol_white_square_tl } \, 2 \, 年 \, /
           \, { \c__sjtu_symbol_white_square_tl } \, 3 \, 年，
      过保密期后适用本授权书。 \par
    { \c__sjtu_symbol_white_square_tl } \, \textbf { 秘密论文 }，
      保密 \, \underline { \hspace { 2 em } } \, 年（不超过~ 10~ 年），
      过保密期后适用本授权书。 \par
    { \c__sjtu_symbol_white_square_tl } \, \textbf { 机密论文 }，
      保密 \, \underline { \hspace { 2 em } } \, 年（不超过~ 20~ 年），
      过保密期后适用本授权书。 \par
    \hspace { 6 em }（请在以上方框内选择打“ \ensuremath { \checkmark } ”）
  }
\tl_const:Nn \c__sjtu_signature_text_zh_tl
  {
    签名： \\
    日期： \hspace { \stretch { 3 } } 年
           \hspace { \stretch { 2 } } 月
           \hspace { \stretch { 2 } } 日
  }
\cs_new_protected:Npn \__sjtu_signature:N #1
  {
    \parbox [ t ] { 12 em }
      { #1 \c__sjtu_signature_text_zh_tl }
  }
\clist_map_inline:nn
  {
    { orig / title }
      {
        format      = \zihao { 3 } \setbaselineskip { 30 bp }
                      \bfseries \heiti ,
        content     =
          {
            \c__sjtu_name_univ_zh_tl
            \skip_vertical:N \c_zero_skip
            \c__sjtu_name_thesis_zh_tl
            \c__sjtu_name_orig_decl_zh_tl
          } ,
        bottom-skip = 12 bp
      },
    { orig / text  }
      {
        format      = \zihao { -4 } \setbaselineskip { 24 bp } ,
        bottom-skip = 24 bp ,
        align       = normal
      },
    { orig / sign  }
      {
        format      = \zihao { 4 } \setbaselineskip { 30 bp } ,
        content     =
          {
            \__sjtu_signature:N \c__sjtu_name_decl_author_zh_tl
            \skip_horizontal:n { 2 em } \hbox:n { }
          } ,
        bottom-skip = 24 bp plus 1 fill ,
        align       = right
      },
    { auth / title }
      {
        format      = \zihao { 3 } \setbaselineskip { 30 bp }
                      \bfseries \heiti ,
        content     =
          {
            \c__sjtu_name_univ_zh_tl
            \skip_vertical:N \c_zero_skip
            \c__sjtu_name_thesis_zh_tl
            \c__sjtu_name_auth_decl_zh_tl
          } ,
        bottom-skip = 12 bp
      },
    { auth / text  }
      {
        format      = \zihao { -4 } \setbaselineskip { 24 bp } ,
        content     = \c__sjtu_auth_decl_text_zh_tl ,
        bottom-skip = 24 bp ,
        align       = normal
      },
    { auth / sign  }
      {
        format      = \zihao { 4 } \setbaselineskip { 30 bp } ,
        content     =
          {
            \__sjtu_signature:N \c__sjtu_name_decl_author_zh_tl
            \hfill
            \__sjtu_signature:N \c__sjtu_name_decl_supervisor_zh_tl
          } ,
        bottom-skip = \c_zero_dim plus 1 fill ,
        align       = normal
      }
  }
  {
    \__sjtu_declare_element_instance:nnn { copyright } #1
  }
\__sjtu_declare_page_instance:nnn { copyright }
  {
    bookmark  = \tl_use:c { c__sjtu_name_declaration_ \g__sjtu_lang_tl _tl } ,
    precode   = \newgeometry
                  {
                    margin        = 3.0 cm ,
                    bindingoffset = 0.5 cm
                  } ,
    prefix    = copyright ,
    elements  =
      {
        orig / title, orig / text, orig / sign,
        auth / title, auth / text, auth / sign
      }
  }
\tl_new:N \l__sjtu_copyright_page_file_tl
\keys_define:nn { sjtu / private / copyright }
  {
    file .tl_set:N = \l__sjtu_copyright_page_file_tl ,
    file .value_required:n = true ,
    filename .meta:n = { file = #1 } ,
    variant .choice: ,
    variant .choices:nn =
      { a, b }
      {
        \EditInstance { sjtu / element } { copyright / orig / text }
          { content = \tl_use:c { c__sjtu_orig_decl_text_ #1 _zh_tl } }
      } ,
    variant  .initial:n = a
  }
\msg_new:nnn { sjtutex } { require-pdfpages }
  {
    Add~'\token_to_str:N \usepackage{pdfpages}'~in~your~preamble \\
    before~inserting~pages~of~external~PDF.
  }
\RenewDocumentCommand \copyrightpage { O{ } }
  {
    \bool_if:NF \g__sjtu_review_bool
      {
        \group_begin:
          \keys_set_known:nnN { sjtu / private / copyright }
            {#1} \l__sjtu_tmp_tl
          \tl_if_empty:NTF \l__sjtu_copyright_page_file_tl
            { \UseInstance { sjtu / page } { copyright } { zh } }
            {
              \cs_if_exist:NTF \includepdf
                {
                  \legacy_if:nTF { @openright }
                    { \cleardoublepage } { \clearpage }
                  \exp_args:Nnv \__sjtu_pdf_bookmark:nn
                    { 0 } { c__sjtu_name_declaration_ \g__sjtu_lang_tl _tl }
                  \tl_set_rescan:NnV \l__sjtu_tmp_tl { } \l__sjtu_tmp_tl
                  \exp_args:NNo \includepdf [ \l__sjtu_tmp_tl ]
                    { \l__sjtu_copyright_page_file_tl }
                }
                {
                  \msg_warning:nn { sjtutex } { require-pdfpages }
                  \UseInstance { sjtu / page } { copyright } { zh }
                }
            }
        \group_end:
      }
  }
\AddToHook { env / abstract / end }
  {
    \clist_if_empty:cF { l__sjtu_info_keywords_ \l__sjtu_lang_tl _clist }
      {
        \par \mode_leave_vertical: \par
        \__sjtu_keywords_format:n
          {
            \tl_use:c { c__sjtu_name_keywords_ \l__sjtu_lang_tl _tl }
            \tl_use:c { c__sjtu_name_info_sep_ \l__sjtu_lang_tl _tl }
          }
        \clist_use:cv { l__sjtu_info_keywords_ \l__sjtu_lang_tl _clist }
          { c__sjtu_name_item_sep_ \l__sjtu_lang_tl _tl }
        \par
      }
  }
\tl_set:Nn \SJTU@leaders { \titlerule* [ 4bp ] { . } }
\contentsmargin [ 2.55 em ] { 0 pt }
\titlecontents { chapter }
  [ 0 pt ] { \addvspace { 6 bp } \bfseries }
  { \contentspush { \thecontentslabel \enskip } } { }
  { \SJTU@leaders \thecontentspage }
\titlecontents { section }
  [ 2 em ] { }
  { \contentspush { \thecontentslabel \enskip } } { }
  { \SJTU@leaders \thecontentspage }
\titlecontents { subsection }
  [ 4 em ] { }
  { \contentspush { \thecontentslabel \enskip } } { }
  { \SJTU@leaders \thecontentspage }
\NewDocumentCommand \SJTU@titlecontents { m O{\csname ext@#1\endcsname} m o }
  {
    \IfNoValueTF {#4}
      {
        \titlecontents {#1}
          [ 0 pt ] { }
          { \contentspush { #3 \thecontentslabel \enskip } } { }
          { \SJTU@leaders \thecontentspage }
      }
      {
        \titlecontents {#1}
          [#4] { }
          { \contentslabel [ #3 \thecontentslabel ] {#4} }
          { \hspace* { - #4 } }
          { \SJTU@leaders \thecontentspage }
      }
    \contentsuse {#1} {#2}
  }
\SJTU@titlecontents { figure } { \figurename \space }
\SJTU@titlecontents { table  } { \tablename  \space }
\NewHook { sjtutex / digest }
\RenewDocumentEnvironment { digest } { O{ } +b }
  {
    \AtEndDocument
      {
        \group_begin:
          \__sjtu_select_language:n { en, #1 }
          \legacy_if:nTF { @openright }
            { \cleardoublepage } { \clearpage }
          \pagenumbering { roman }
          \tl_gset:Nn \__sjtu_the_page_tl { \arabic { page } }
          \UseHook { sjtutex / digest }
          \cs_gset_eq:NN \addcontentsline \use_none:nnn
          \clist_map_inline:Nn \l__sjtu_counter_without_chapter_clist
            {
              \counterwithout {##1} { chapter }
              \setcounter     {##1} { 0 }
            }
          \tl_set_eq:Nc \l__sjtu_heading_title_tl
            { l__sjtu_info_display_title_ \l__sjtu_lang_tl _tl }
          \__sjtu_make_heading:n { marking = \SJTU@digestname, #1, notintoc }
          #2
        \group_end:
      }
  } { }
\ctex_at_end_package:nn { hyperref }
  {
    \ctex_after_end_preamble:n
      {
        \hypersetup
          {
            pdfsubject  = \l__sjtu_info_subject_zh_tl ,
            pdfkeywords = \l__sjtu_info_keywords_zh_clist
          }
      }
  }
\ctex_at_end_package:nn { pageslts }
  {
    \AddToHook { sjtutex / digest }
      {
        \tl_gset:Nn \__sjtu_the_last_page_tl
          { \lastpageref { pagesLTS.roman.local } }
      }
  }
\ctex_at_end_package:nn { thmtools }
  {
    \cs_set:Npn \thmtlo@newentry
      {
        \exp_args:NV \SJTU@titlecontents \thmt@envname [ loe ]
          { } [ \thmt@listnumwidth ]
      }
  }
\ctex_at_end_package:nn { algorithm }
  { \SJTU@titlecontents { algorithm } { \fname@algorithm \space } }
\ctex_at_end_package:nn { algorithm2e }
  { \SJTU@titlecontents { algocf } { \algorithmcfname \space } }
\endinput
%%
%% End of file `sjtu-thesis-preset-base.def'.
