%%
%% This is file `l3coffins.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% l3coffins.dtx  (with options: `package')
%% 
%% EXPERIMENTAL CODE
%% 
%% Do not distribute this file without also distributing the
%% source files specified above.
%% 
%% Do not distribute a modified version of this file.
%% 
%% File: l3coffins.dtx Copyright(C) 2010-2012 The LaTeX3 Project
%%
%% It may be distributed and/or modified under the conditions of the
%% LaTeX Project Public License (LPPL), either version 1.3c of this
%% license or (at your option) any later version.  The latest version
%% of this license is in the file
%%
%%    http://www.latex-project.org/lppl.txt
%%
%% This file is part of the "l3kernel bundle" (The Work in LPPL)
%% and all files in that bundle must be distributed together.
%%
%% The released version of this bundle is available from CTAN.
%%
%% -----------------------------------------------------------------------
%%
%% The development version of the bundle can be found at
%%
%%    http://www.latex-project.org/svnroot/experimental/trunk/
%%
%% for those people who are interested.
%%
%%%%%%%%%%%
%% NOTE: %%
%%%%%%%%%%%
%%
%%   Snapshots taken from the repository represent work in progress and may
%%   not work or may contain conflicting material!  We therefore ask
%%   people _not_ to put them into distributions, archives, etc. without
%%   prior consultation with the LaTeX Project Team.
%%
%% -----------------------------------------------------------------------
%%
\RequirePackage{l3bootstrap}
\GetIdInfo$Id: l3coffins.dtx 4212 2012-09-09 12:24:04Z bruno $
  {L3 Coffin code layer}
\ProvidesExplPackage
  {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
\__expl_package_check:
\box_new:N \l__coffin_internal_box
\dim_new:N \l__coffin_internal_dim
\tl_new:N  \l__coffin_internal_tl
\prop_new:N \c__coffin_corners_prop
\prop_put:Nnn \c__coffin_corners_prop { tl } { { 0 pt } { 0 pt } }
\prop_put:Nnn \c__coffin_corners_prop { tr } { { 0 pt } { 0 pt } }
\prop_put:Nnn \c__coffin_corners_prop { bl } { { 0 pt } { 0 pt } }
\prop_put:Nnn \c__coffin_corners_prop { br } { { 0 pt } { 0 pt } }
\prop_new:N \c__coffin_poles_prop
\tl_set:Nn \l__coffin_internal_tl { { 0 pt } { 0 pt } { 0 pt } { 1000 pt } }
\prop_put:Nno \c__coffin_poles_prop { l }  { \l__coffin_internal_tl }
\prop_put:Nno \c__coffin_poles_prop { hc } { \l__coffin_internal_tl }
\prop_put:Nno \c__coffin_poles_prop { r }  { \l__coffin_internal_tl }
\tl_set:Nn \l__coffin_internal_tl { { 0 pt } { 0 pt } { 1000 pt } { 0 pt } }
\prop_put:Nno \c__coffin_poles_prop { b }  { \l__coffin_internal_tl }
\prop_put:Nno \c__coffin_poles_prop { vc } { \l__coffin_internal_tl }
\prop_put:Nno \c__coffin_poles_prop { t }  { \l__coffin_internal_tl }
\prop_put:Nno \c__coffin_poles_prop { B }  { \l__coffin_internal_tl }
\prop_put:Nno \c__coffin_poles_prop { H }  { \l__coffin_internal_tl }
\prop_put:Nno \c__coffin_poles_prop { T }  { \l__coffin_internal_tl }
\fp_new:N \l__coffin_slope_x_fp
\fp_new:N \l__coffin_slope_y_fp
\bool_new:N \l__coffin_error_bool
\dim_new:N \l__coffin_offset_x_dim
\dim_new:N \l__coffin_offset_y_dim
\tl_new:N \l__coffin_pole_a_tl
\tl_new:N \l__coffin_pole_b_tl
\dim_new:N \l__coffin_x_dim
\dim_new:N \l__coffin_y_dim
\dim_new:N \l__coffin_x_prime_dim
\dim_new:N \l__coffin_y_prime_dim
\prg_new_conditional:Npnn \coffin_if_exist:N #1 { p , T , F , TF }
  {
    \cs_if_exist:NTF #1
      {
        \cs_if_exist:cTF { l__coffin_poles_ \__int_value:w #1 _prop }
          { \prg_return_true: }
          { \prg_return_false: }
      }
      { \prg_return_false: }
  }
\cs_generate_variant:Nn \coffin_if_exist_p:N { c }
\cs_generate_variant:Nn \coffin_if_exist:NT  { c }
\cs_generate_variant:Nn \coffin_if_exist:NF  { c }
\cs_generate_variant:Nn \coffin_if_exist:NTF { c }
\cs_new_protected:Npn \__coffin_if_exist:NT #1#2
  {
    \coffin_if_exist:NTF #1
      { #2 }
      {
        \__msg_kernel_error:nnx { kernel } { unknown-coffin }
          { \token_to_str:N #1 }
      }
  }
\cs_new_protected:Npn \coffin_clear:N #1
  {
    \__coffin_if_exist:NT #1
      {
        \box_clear:N #1
        \__coffin_reset_structure:N #1
      }
  }
\cs_generate_variant:Nn \coffin_clear:N { c }
\cs_new_protected:Npn \coffin_new:N #1
  {
    \box_new:N #1
    \prop_clear_new:c { l__coffin_corners_ \__int_value:w #1 _prop }
    \prop_clear_new:c { l__coffin_poles_   \__int_value:w #1 _prop }
    \prop_gset_eq:cN { l__coffin_corners_ \__int_value:w #1 _prop }
      \c__coffin_corners_prop
    \prop_gset_eq:cN { l__coffin_poles_ \__int_value:w #1 _prop }
      \c__coffin_poles_prop
  }
\cs_generate_variant:Nn \coffin_new:N { c }
\cs_new_protected:Npn \hcoffin_set:Nn #1#2
  {
    \__coffin_if_exist:NT #1
      {
        \hbox_set:Nn #1
          {
            \color_group_begin:
              \color_ensure_current:
              #2
            \color_group_end:
          }
        \__coffin_reset_structure:N #1
        \__coffin_update_poles:N #1
        \__coffin_update_corners:N #1
      }
  }
\cs_generate_variant:Nn \hcoffin_set:Nn { c }
\cs_new_protected:Npn \vcoffin_set:Nnn #1#2#3
  {
    \__coffin_if_exist:NT #1
      {
        \vbox_set:Nn #1
          {
            \dim_set:Nn \tex_hsize:D {#2}
            \dim_set_eq:NN \linewidth   \tex_hsize:D
            \dim_set_eq:NN \columnwidth \tex_hsize:D
            \color_group_begin:
              #3
            \color_group_end:
          }
        \__coffin_reset_structure:N #1
        \__coffin_update_poles:N #1
        \__coffin_update_corners:N #1
        \vbox_set_top:Nn \l__coffin_internal_box { \vbox_unpack:N #1 }
        \__coffin_set_pole:Nnx #1 { T }
          {
            { 0 pt }
            { \dim_eval:n { \box_ht:N #1 - \box_ht:N \l__coffin_internal_box } }
            { 1000 pt }
            { 0 pt }
          }
        \box_clear:N \l__coffin_internal_box
      }
  }
\cs_generate_variant:Nn \vcoffin_set:Nnn { c }
\cs_new_protected:Npn \hcoffin_set:Nw #1
  {
    \__coffin_if_exist:NT #1
      {
        \hbox_set:Nw #1 \color_group_begin: \color_ensure_current:
          \cs_set_protected_nopar:Npn \hcoffin_set_end:
            {
                \color_group_end:
              \hbox_set_end:
              \__coffin_reset_structure:N #1
              \__coffin_update_poles:N #1
              \__coffin_update_corners:N #1
            }
      }
  }
\cs_new_protected_nopar:Npn \hcoffin_set_end: { }
\cs_generate_variant:Nn \hcoffin_set:Nw { c }
\cs_new_protected:Npn \vcoffin_set:Nnw #1#2
  {
    \__coffin_if_exist:NT #1
      {
        \vbox_set:Nw #1
          \dim_set:Nn \tex_hsize:D {#2}
            \dim_set_eq:NN \linewidth   \tex_hsize:D
            \dim_set_eq:NN \columnwidth \tex_hsize:D
          \color_group_begin: \color_ensure_current:
          \cs_set_protected:Npn \vcoffin_set_end:
            {
                \color_group_end:
              \vbox_set_end:
              \__coffin_reset_structure:N #1
              \__coffin_update_poles:N #1
              \__coffin_update_corners:N #1
              \vbox_set_top:Nn \l__coffin_internal_box { \vbox_unpack:N #1 }
              \__coffin_set_pole:Nnx #1 { T }
                {
                  { 0 pt }
                  {
                    \dim_eval:n { \box_ht:N #1 - \box_ht:N \l__coffin_internal_box }
                  }
                  { 1000 pt }
                  { 0 pt }
                }
              \box_clear:N \l__coffin_internal_box
            }
      }
  }
\cs_new_protected_nopar:Npn \vcoffin_set_end: { }
\cs_generate_variant:Nn \vcoffin_set:Nnw { c }
\cs_new_protected:Npn \coffin_set_eq:NN #1#2
  {
    \__coffin_if_exist:NT #1
      {
        \box_set_eq:NN #1 #2
        \__coffin_set_eq_structure:NN #1 #2
      }
  }
\cs_generate_variant:Nn \coffin_set_eq:NN { c , Nc , cc }
\coffin_new:N \c_empty_coffin
\hbox_set:Nn  \c_empty_coffin { }
\coffin_new:N \l__coffin_aligned_coffin
\coffin_new:N \l__coffin_aligned_internal_coffin
\coffin_new:N \l_tmpa_coffin
\coffin_new:N \l_tmpb_coffin
\cs_new_eq:NN \coffin_dp:N \box_dp:N
\cs_new_eq:NN \coffin_dp:c \box_dp:c
\cs_new_eq:NN \coffin_ht:N \box_ht:N
\cs_new_eq:NN \coffin_ht:c \box_ht:c
\cs_new_eq:NN \coffin_wd:N \box_wd:N
\cs_new_eq:NN \coffin_wd:c \box_wd:c
\cs_new_protected:Npn \__coffin_get_pole:NnN #1#2#3
  {
    \prop_get:cnNF
      { l__coffin_poles_ \__int_value:w #1 _prop } {#2} #3
      {
        \__msg_kernel_error:nnxx { kernel } { unknown-coffin-pole }
          {#2} { \token_to_str:N #1 }
        \tl_set:Nn #3 { { 0 pt } { 0 pt } { 0 pt } { 0 pt } }
      }
  }
\cs_new_protected:Npn \__coffin_reset_structure:N #1
  {
    \prop_set_eq:cN { l__coffin_corners_ \__int_value:w #1 _prop }
      \c__coffin_corners_prop
    \prop_set_eq:cN { l__coffin_poles_ \__int_value:w #1 _prop }
      \c__coffin_poles_prop
  }
\cs_new_protected:Npn \__coffin_set_eq_structure:NN #1#2
  {
    \prop_set_eq:cc { l__coffin_corners_ \__int_value:w #1 _prop }
      { l__coffin_corners_ \__int_value:w #2 _prop }
    \prop_set_eq:cc { l__coffin_poles_ \__int_value:w #1 _prop }
      { l__coffin_poles_ \__int_value:w #2 _prop }
  }
\cs_new_protected:Npn \__coffin_gset_eq_structure:NN #1#2
  {
    \prop_gset_eq:cc { l__coffin_corners_ \__int_value:w #1 _prop }
      { l__coffin_corners_ \__int_value:w #2 _prop }
    \prop_gset_eq:cc { l__coffin_poles_ \__int_value:w #1 _prop }
      { l__coffin_poles_ \__int_value:w #2 _prop }
  }
\cs_new_protected:Npn \coffin_set_horizontal_pole:Nnn #1#2#3
  {
    \__coffin_if_exist:NT #1
      {
        \__coffin_set_pole:Nnx #1 {#2}
          {
            { 0 pt } { \dim_eval:n {#3} }
            { 1000 pt } { 0 pt }
          }
      }
  }
\cs_new_protected:Npn \coffin_set_vertical_pole:Nnn #1#2#3
  {
    \__coffin_if_exist:NT #1
      {
        \__coffin_set_pole:Nnx #1 {#2}
          {
            { \dim_eval:n {#3} } { 0 pt }
            { 0 pt } { 1000 pt }
          }
      }
  }
\cs_new_protected:Npn \__coffin_set_pole:Nnn #1#2#3
  { \prop_put:cnn { l__coffin_poles_ \__int_value:w #1 _prop } {#2} {#3} }
\cs_generate_variant:Nn \coffin_set_horizontal_pole:Nnn { c }
\cs_generate_variant:Nn \coffin_set_vertical_pole:Nnn { c }
\cs_generate_variant:Nn \__coffin_set_pole:Nnn { Nnx }
\cs_new_protected:Npn \__coffin_update_corners:N #1
  {
    \prop_put:cnx { l__coffin_corners_ \__int_value:w #1 _prop } { tl }
      { { 0 pt } { \dim_use:N \box_ht:N #1 } }
    \prop_put:cnx { l__coffin_corners_ \__int_value:w #1 _prop } { tr }
      { { \dim_use:N \box_wd:N #1 } { \dim_use:N \box_ht:N #1 } }
    \prop_put:cnx { l__coffin_corners_ \__int_value:w #1 _prop } { bl }
      { { 0 pt } { \dim_eval:n { - \box_dp:N #1 } } }
    \prop_put:cnx { l__coffin_corners_ \__int_value:w #1 _prop } { br }
      { { \dim_use:N \box_wd:N #1 } { \dim_eval:n { - \box_dp:N #1 } } }
  }
\cs_new_protected:Npn \__coffin_update_poles:N #1
  {
    \prop_put:cnx { l__coffin_poles_ \__int_value:w #1 _prop } { hc }
      {
        { \dim_eval:n { 0.5 \box_wd:N #1 } }
        { 0 pt } { 0 pt } { 1000 pt }
      }
    \prop_put:cnx { l__coffin_poles_ \__int_value:w #1 _prop } { r }
      {
        { \dim_use:N \box_wd:N #1 }
        { 0 pt } { 0 pt } { 1000 pt }
      }
    \prop_put:cnx { l__coffin_poles_ \__int_value:w #1 _prop } { vc }
      {
        { 0 pt }
        { \dim_eval:n { ( \box_ht:N #1 - \box_dp:N #1 ) / 2 } }
        { 1000 pt }
        { 0 pt }
      }
    \prop_put:cnx { l__coffin_poles_ \__int_value:w #1 _prop } { t }
      {
        { 0 pt }
        { \dim_use:N \box_ht:N #1 }
        { 1000 pt }
        { 0 pt }
      }
    \prop_put:cnx { l__coffin_poles_ \__int_value:w #1 _prop } { b }
      {
        { 0 pt }
        { \dim_eval:n { - \box_dp:N #1 } }
        { 1000 pt }
        { 0 pt }
      }
  }
\cs_new_protected:Npn \__coffin_calculate_intersection:Nnn #1#2#3
  {
    \__coffin_get_pole:NnN #1 {#2} \l__coffin_pole_a_tl
    \__coffin_get_pole:NnN #1 {#3} \l__coffin_pole_b_tl
    \bool_set_false:N \l__coffin_error_bool
    \exp_last_two_unbraced:Noo
      \__coffin_calculate_intersection:nnnnnnnn
        \l__coffin_pole_a_tl \l__coffin_pole_b_tl
    \bool_if:NT \l__coffin_error_bool
      {
        \__msg_kernel_error:nn { kernel } { no-pole-intersection }
        \dim_zero:N \l__coffin_x_dim
        \dim_zero:N \l__coffin_y_dim
      }
  }
\cs_new_protected:Npn \__coffin_calculate_intersection:nnnnnnnn
  #1#2#3#4#5#6#7#8
  {
    \dim_compare:nNnTF {#3} = { \c_zero_dim }
      {
        \dim_set:Nn \l__coffin_x_dim {#1}
        \dim_compare:nNnTF {#7} = \c_zero_dim
          { \bool_set_true:N \l__coffin_error_bool }
          {
            \dim_compare:nNnTF {#8} = \c_zero_dim
              { \dim_set:Nn \l__coffin_y_dim {#6} }
              {
                \__coffin_calculate_intersection_aux:nnnnnN
                  {#1} {#5} {#6} {#7} {#8} \l__coffin_y_dim
              }
          }
      }
      {
        \dim_compare:nNnTF {#4} = \c_zero_dim
          {
            \dim_set:Nn \l__coffin_y_dim {#2}
            \dim_compare:nNnTF {#8} = { \c_zero_dim }
              { \bool_set_true:N \l__coffin_error_bool }
              {
                \dim_compare:nNnTF {#7} = \c_zero_dim
                  { \dim_set:Nn \l__coffin_x_dim {#5} }
                  {
                    \__coffin_calculate_intersection_aux:nnnnnN
                      {#2} {#6} {#5} {#8} {#7} \l__coffin_x_dim
                  }
              }
          }
          {
            \dim_compare:nNnTF {#7} = \c_zero_dim
              {
                \dim_set:Nn \l__coffin_x_dim {#5}
                \__coffin_calculate_intersection_aux:nnnnnN
                  {#5} {#1} {#2} {#3} {#4} \l__coffin_y_dim
              }
              {
                \dim_compare:nNnTF {#8} = \c_zero_dim
                  {
                    \dim_set:Nn \l__coffin_x_dim {#6}
                    \__coffin_calculate_intersection_aux:nnnnnN
                      {#6} {#2} {#1} {#4} {#3} \l__coffin_x_dim
                  }
                  {
                    \fp_set:Nn \l__coffin_slope_x_fp
                      { \dim_to_fp:n {#4} / \dim_to_fp:n {#3} }
                    \fp_set:Nn \l__coffin_slope_y_fp
                      { \dim_to_fp:n {#8} / \dim_to_fp:n {#7} }
                    \fp_compare:nNnTF
                      \l__coffin_slope_x_fp = \l__coffin_slope_y_fp
                      { \bool_set_true:N \l__coffin_error_bool }
                      {
                        \dim_set:Nn \l__coffin_x_dim
                          {
                            \fp_to_dim:n
                              {
                                (
                                      \dim_to_fp:n {#1} * \l__coffin_slope_x_fp
                                  - ( \dim_to_fp:n {#5} * \l__coffin_slope_y_fp )
                                  -   \dim_to_fp:n {#2}
                                  +   \dim_to_fp:n {#6}
                                )
                                /
                                ( \l__coffin_slope_x_fp - \l__coffin_slope_y_fp )
                            }
                          }
                        \__coffin_calculate_intersection_aux:nnnnnN
                          { \l__coffin_x_dim }
                          {#5} {#6} {#8} {#7} \l__coffin_y_dim
                      }
                  }
              }
          }
      }
  }
\cs_new_protected:Npn \__coffin_calculate_intersection_aux:nnnnnN #1#2#3#4#5#6
  {
    \dim_set:Nn #6
      {
        \fp_to_dim:n
          {
            \dim_to_fp:n {#4} *
            ( \dim_to_fp:n {#1} - \dim_to_fp:n {#2} ) /
            \dim_to_fp:n {#5}
            + \dim_to_fp:n {#3}
          }
      }
  }
\cs_new_protected:Npn \coffin_join:NnnNnnnn #1#2#3#4#5#6#7#8
  {
    \__coffin_align:NnnNnnnnN
      #1 {#2} {#3} #4 {#5} {#6} {#7} {#8} \l__coffin_aligned_coffin
    \hbox_set:Nn \l__coffin_aligned_coffin
      {
        \dim_compare:nNnT { \l__coffin_offset_x_dim } < \c_zero_dim
          { \tex_kern:D -\l__coffin_offset_x_dim }
        \hbox_unpack:N \l__coffin_aligned_coffin
        \dim_set:Nn \l__coffin_internal_dim
          { \l__coffin_offset_x_dim - \box_wd:N #1 + \box_wd:N #4 }
        \dim_compare:nNnT \l__coffin_internal_dim < \c_zero_dim
          { \tex_kern:D -\l__coffin_internal_dim }
      }
   \__coffin_reset_structure:N \l__coffin_aligned_coffin
    \prop_clear:c
      {  l__coffin_corners_ \__int_value:w \l__coffin_aligned_coffin _ prop }
    \__coffin_update_poles:N \l__coffin_aligned_coffin
    \dim_compare:nNnTF \l__coffin_offset_x_dim < \c_zero_dim
      {
        \__coffin_offset_poles:Nnn #1 { -\l__coffin_offset_x_dim } { 0 pt }
        \__coffin_offset_poles:Nnn #4 { 0 pt } { \l__coffin_offset_y_dim }
        \__coffin_offset_corners:Nnn #1 { -\l__coffin_offset_x_dim } { 0 pt }
        \__coffin_offset_corners:Nnn #4 { 0 pt } { \l__coffin_offset_y_dim }
      }
      {
        \__coffin_offset_poles:Nnn #1 { 0 pt } { 0 pt }
        \__coffin_offset_poles:Nnn #4
          { \l__coffin_offset_x_dim } { \l__coffin_offset_y_dim }
        \__coffin_offset_corners:Nnn #1 { 0 pt } { 0 pt }
        \__coffin_offset_corners:Nnn #4
          { \l__coffin_offset_x_dim } { \l__coffin_offset_y_dim }
      }
    \__coffin_update_vertical_poles:NNN #1 #4 \l__coffin_aligned_coffin
    \coffin_set_eq:NN #1 \l__coffin_aligned_coffin
  }
\cs_generate_variant:Nn \coffin_join:NnnNnnnn { c , Nnnc , cnnc }
\cs_new_protected:Npn \coffin_attach:NnnNnnnn #1#2#3#4#5#6#7#8
  {
    \__coffin_align:NnnNnnnnN
      #1 {#2} {#3} #4 {#5} {#6} {#7} {#8} \l__coffin_aligned_coffin
    \box_set_ht:Nn \l__coffin_aligned_coffin { \box_ht:N #1 }
    \box_set_dp:Nn \l__coffin_aligned_coffin { \box_dp:N #1 }
    \box_set_wd:Nn \l__coffin_aligned_coffin { \box_wd:N #1 }
    \__coffin_reset_structure:N \l__coffin_aligned_coffin
    \prop_set_eq:cc
      { l__coffin_corners_ \__int_value:w \l__coffin_aligned_coffin _prop }
      { l__coffin_corners_ \__int_value:w #1 _prop }
    \__coffin_update_poles:N  \l__coffin_aligned_coffin
    \__coffin_offset_poles:Nnn #1 { 0 pt } { 0 pt }
    \__coffin_offset_poles:Nnn #4
      { \l__coffin_offset_x_dim } { \l__coffin_offset_y_dim }
    \__coffin_update_vertical_poles:NNN #1 #4 \l__coffin_aligned_coffin
    \coffin_set_eq:NN #1 \l__coffin_aligned_coffin
  }
\cs_new_protected:Npn \coffin_attach_mark:NnnNnnnn #1#2#3#4#5#6#7#8
  {
    \__coffin_align:NnnNnnnnN
      #1 {#2} {#3} #4 {#5} {#6} {#7} {#8} \l__coffin_aligned_coffin
    \box_set_ht:Nn \l__coffin_aligned_coffin { \box_ht:N #1 }
    \box_set_dp:Nn \l__coffin_aligned_coffin { \box_dp:N #1 }
    \box_set_wd:Nn \l__coffin_aligned_coffin { \box_wd:N #1 }
    \box_set_eq:NN #1 \l__coffin_aligned_coffin
  }
\cs_generate_variant:Nn \coffin_attach:NnnNnnnn { c , Nnnc , cnnc }
\cs_new_protected:Npn \__coffin_align:NnnNnnnnN #1#2#3#4#5#6#7#8#9
  {
    \__coffin_calculate_intersection:Nnn #4 {#5} {#6}
    \dim_set:Nn \l__coffin_x_prime_dim { \l__coffin_x_dim }
    \dim_set:Nn \l__coffin_y_prime_dim { \l__coffin_y_dim }
    \__coffin_calculate_intersection:Nnn #1 {#2} {#3}
    \dim_set:Nn \l__coffin_offset_x_dim
      { \l__coffin_x_dim - \l__coffin_x_prime_dim + #7 }
    \dim_set:Nn \l__coffin_offset_y_dim
      { \l__coffin_y_dim - \l__coffin_y_prime_dim + #8 }
    \hbox_set:Nn \l__coffin_aligned_internal_coffin
      {
        \box_use:N #1
        \tex_kern:D -\box_wd:N #1
        \tex_kern:D \l__coffin_offset_x_dim
        \box_move_up:nn { \l__coffin_offset_y_dim } { \box_use:N #4 }
      }
    \coffin_set_eq:NN #9 \l__coffin_aligned_internal_coffin
  }
\cs_new_protected:Npn \__coffin_offset_poles:Nnn #1#2#3
  {
    \prop_map_inline:cn { l__coffin_poles_ \__int_value:w #1 _prop }
      { \__coffin_offset_pole:Nnnnnnn #1 {##1} ##2 {#2} {#3} }
  }
\cs_new_protected:Npn \__coffin_offset_pole:Nnnnnnn #1#2#3#4#5#6#7#8
  {
    \dim_set:Nn \l__coffin_x_dim { #3 + #7 }
    \dim_set:Nn \l__coffin_y_dim { #4 + #8 }
    \tl_if_in:nnTF {#2} { - }
      { \tl_set:Nn \l__coffin_internal_tl { {#2} } }
      { \tl_set:Nn \l__coffin_internal_tl { { #1 - #2 } } }
    \exp_last_unbraced:NNo \__coffin_set_pole:Nnx \l__coffin_aligned_coffin
      { \l__coffin_internal_tl }
      {
        { \dim_use:N \l__coffin_x_dim } { \dim_use:N \l__coffin_y_dim }
        {#5} {#6}
      }
  }
\cs_new_protected:Npn \__coffin_offset_corners:Nnn #1#2#3
  {
    \prop_map_inline:cn { l__coffin_corners_ \__int_value:w #1 _prop }
      { \__coffin_offset_corner:Nnnnn #1 {##1} ##2 {#2} {#3} }
  }
\cs_new_protected:Npn \__coffin_offset_corner:Nnnnn #1#2#3#4#5#6
  {
    \prop_put:cnx
      { l__coffin_corners_ \__int_value:w \l__coffin_aligned_coffin _prop }
      { #1 - #2 }
      {
        { \dim_eval:n { #3 + #5 } }
        { \dim_eval:n { #4 + #6 } }
      }
  }
\cs_new_protected:Npn \__coffin_update_vertical_poles:NNN #1#2#3
  {
    \__coffin_get_pole:NnN #3 { #1 -T } \l__coffin_pole_a_tl
    \__coffin_get_pole:NnN #3 { #2 -T } \l__coffin_pole_b_tl
    \exp_last_two_unbraced:Noo \__coffin_update_T:nnnnnnnnN
      \l__coffin_pole_a_tl \l__coffin_pole_b_tl #3
    \__coffin_get_pole:NnN #3 { #1 -B } \l__coffin_pole_a_tl
    \__coffin_get_pole:NnN #3 { #2 -B } \l__coffin_pole_b_tl
    \exp_last_two_unbraced:Noo \__coffin_update_B:nnnnnnnnN
      \l__coffin_pole_a_tl \l__coffin_pole_b_tl #3
  }
\cs_new_protected:Npn \__coffin_update_T:nnnnnnnnN #1#2#3#4#5#6#7#8#9
  {
    \dim_compare:nNnTF {#2} < {#6}
      {
        \__coffin_set_pole:Nnx #9 { T }
          { { 0 pt } {#6} { 1000 pt } { 0 pt } }
      }
      {
        \__coffin_set_pole:Nnx #9 { T }
          { { 0 pt } {#2} { 1000 pt } { 0 pt } }
      }
  }
\cs_new_protected:Npn \__coffin_update_B:nnnnnnnnN #1#2#3#4#5#6#7#8#9
  {
    \dim_compare:nNnTF {#2} < {#6}
      {
        \__coffin_set_pole:Nnx #9 { B }
          { { 0 pt } {#2}  { 1000 pt } { 0 pt } }
      }
      {
        \__coffin_set_pole:Nnx #9 { B }
          { { 0 pt } {#6} { 1000 pt } { 0 pt } }
      }
  }
\cs_new_protected:Npn \coffin_typeset:Nnnnn #1#2#3#4#5
  {
    \hbox_unpack:N \c_empty_box
    \__coffin_align:NnnNnnnnN \c_empty_coffin { H } { l }
      #1 {#2} {#3} {#4} {#5} \l__coffin_aligned_coffin
    \box_use:N \l__coffin_aligned_coffin
  }
\cs_generate_variant:Nn \coffin_typeset:Nnnnn { c }
\coffin_new:N \l__coffin_display_coffin
\coffin_new:N \l__coffin_display_coord_coffin
\coffin_new:N \l__coffin_display_pole_coffin
\prop_new:N \l__coffin_display_handles_prop
\prop_put:Nnn \l__coffin_display_handles_prop { tl }
  { { b } { r } { -1 } { 1 } }
\prop_put:Nnn \l__coffin_display_handles_prop { thc }
  { { b } { hc } { 0 } { 1 } }
\prop_put:Nnn \l__coffin_display_handles_prop { tr }
  { { b } { l } { 1 } { 1 } }
\prop_put:Nnn \l__coffin_display_handles_prop { vcl }
  { { vc } { r } { -1 } { 0 } }
\prop_put:Nnn \l__coffin_display_handles_prop { vchc }
  { { vc } { hc } { 0 } { 0 } }
\prop_put:Nnn \l__coffin_display_handles_prop { vcr }
  { { vc } { l } { 1 } { 0 } }
\prop_put:Nnn \l__coffin_display_handles_prop { bl }
  { { t } { r } { -1 } { -1 } }
\prop_put:Nnn \l__coffin_display_handles_prop { bhc }
  { { t } { hc } { 0 } { -1 } }
\prop_put:Nnn \l__coffin_display_handles_prop { br }
  { { t } { l } { 1 } { -1 } }
\prop_put:Nnn \l__coffin_display_handles_prop { Tl }
  { { t } { r } { -1 } { -1 } }
\prop_put:Nnn \l__coffin_display_handles_prop { Thc }
  { { t } { hc } { 0 } { -1 } }
\prop_put:Nnn \l__coffin_display_handles_prop { Tr }
  { { t } { l } { 1 } { -1 } }
\prop_put:Nnn \l__coffin_display_handles_prop { Hl }
  { { vc } { r } { -1 } { 1 } }
\prop_put:Nnn \l__coffin_display_handles_prop { Hhc }
  { { vc } { hc } { 0 } { 1 } }
\prop_put:Nnn \l__coffin_display_handles_prop { Hr }
  { { vc } { l } { 1 } { 1 } }
\prop_put:Nnn \l__coffin_display_handles_prop { Bl }
  { { b } { r } { -1 } { -1 } }
\prop_put:Nnn \l__coffin_display_handles_prop { Bhc }
  { { b } { hc } { 0 } { -1 } }
\prop_put:Nnn \l__coffin_display_handles_prop { Br }
  { { b } { l } { 1 } { -1 } }
\dim_new:N  \l__coffin_display_offset_dim
\dim_set:Nn \l__coffin_display_offset_dim { 2 pt }
\dim_new:N \l__coffin_display_x_dim
\dim_new:N \l__coffin_display_y_dim
\prop_new:N \l__coffin_display_poles_prop
\tl_new:N  \l__coffin_display_font_tl
\tl_set:Nn \l__coffin_display_font_tl { \sffamily \tiny }
\cs_new_protected:Npn \coffin_mark_handle:Nnnn #1#2#3#4
  {
    \hcoffin_set:Nn \l__coffin_display_pole_coffin
      {
        \color {#4}
        \rule { 1 pt } { 1 pt }
      }
    \coffin_attach_mark:NnnNnnnn #1 {#2} {#3}
      \l__coffin_display_pole_coffin { hc } { vc } { 0 pt } { 0 pt }
    \hcoffin_set:Nn \l__coffin_display_coord_coffin
      {
        \color {#4}
        \l__coffin_display_font_tl
        ( \tl_to_str:n { #2 , #3 } )
      }
    \prop_get:NnN \l__coffin_display_handles_prop
      { #2 #3 } \l__coffin_internal_tl
    \quark_if_no_value:NTF \l__coffin_internal_tl
      {
        \prop_get:NnN \l__coffin_display_handles_prop
          { #3 #2 } \l__coffin_internal_tl
        \quark_if_no_value:NTF \l__coffin_internal_tl
          {
            \coffin_attach_mark:NnnNnnnn #1 {#2} {#3}
              \l__coffin_display_coord_coffin { l } { vc }
                { 1 pt } { 0 pt }
          }
          {
            \exp_last_unbraced:No \__coffin_mark_handle_aux:nnnnNnn
              \l__coffin_internal_tl #1 {#2} {#3}
          }
      }
      {
        \exp_last_unbraced:No \__coffin_mark_handle_aux:nnnnNnn
          \l__coffin_internal_tl #1 {#2} {#3}
      }
  }
\cs_new_protected:Npn \__coffin_mark_handle_aux:nnnnNnn #1#2#3#4#5#6#7
  {
    \coffin_attach_mark:NnnNnnnn #5 {#6} {#7}
      \l__coffin_display_coord_coffin {#1} {#2}
      { #3 \l__coffin_display_offset_dim }
      { #4 \l__coffin_display_offset_dim }
  }
\cs_generate_variant:Nn \coffin_mark_handle:Nnnn { c }
\cs_new_protected:Npn \coffin_display_handles:Nn #1#2
  {
    \hcoffin_set:Nn \l__coffin_display_pole_coffin
      {
        \color {#2}
        \rule { 1 pt } { 1 pt }
      }
    \prop_set_eq:Nc \l__coffin_display_poles_prop
      { l__coffin_poles_ \__int_value:w #1 _prop }
    \__coffin_get_pole:NnN #1 { H } \l__coffin_pole_a_tl
    \__coffin_get_pole:NnN #1 { T } \l__coffin_pole_b_tl
    \tl_if_eq:NNT \l__coffin_pole_a_tl \l__coffin_pole_b_tl
      { \prop_remove:Nn \l__coffin_display_poles_prop { T } }
    \__coffin_get_pole:NnN #1 { B } \l__coffin_pole_b_tl
    \tl_if_eq:NNT \l__coffin_pole_a_tl \l__coffin_pole_b_tl
      { \prop_remove:Nn \l__coffin_display_poles_prop { B } }
    \coffin_set_eq:NN \l__coffin_display_coffin #1
    \prop_map_inline:Nn \l__coffin_display_poles_prop
      {
        \prop_remove:Nn \l__coffin_display_poles_prop {##1}
        \__coffin_display_handles_aux:nnnnnn {##1} ##2 {#2}
      }
    \box_use:N \l__coffin_display_coffin
  }
\cs_new_protected:Npn \__coffin_display_handles_aux:nnnnnn #1#2#3#4#5#6
  {
    \prop_map_inline:Nn \l__coffin_display_poles_prop
      {
        \bool_set_false:N \l__coffin_error_bool
        \__coffin_calculate_intersection:nnnnnnnn {#2} {#3} {#4} {#5} ##2
        \bool_if:NF \l__coffin_error_bool
          {
            \dim_set:Nn \l__coffin_display_x_dim { \l__coffin_x_dim }
            \dim_set:Nn \l__coffin_display_y_dim { \l__coffin_y_dim }
            \__coffin_display_attach:Nnnnn
              \l__coffin_display_pole_coffin { hc } { vc }
              { 0 pt } { 0 pt }
            \hcoffin_set:Nn \l__coffin_display_coord_coffin
              {
                \color {#6}
                \l__coffin_display_font_tl
                ( \tl_to_str:n { #1 , ##1 } )
              }
            \prop_get:NnN \l__coffin_display_handles_prop
              { #1 ##1 } \l__coffin_internal_tl
            \quark_if_no_value:NTF \l__coffin_internal_tl
              {
                \prop_get:NnN \l__coffin_display_handles_prop
                  { ##1 #1 } \l__coffin_internal_tl
                \quark_if_no_value:NTF \l__coffin_internal_tl
                  {
                    \__coffin_display_attach:Nnnnn
                      \l__coffin_display_coord_coffin { l } { vc }
                      { 1 pt } { 0 pt }
                  }
                  {
                    \exp_last_unbraced:No
                      \__coffin_display_handles_aux:nnnn
                      \l__coffin_internal_tl
                  }
              }
              {
                \exp_last_unbraced:No \__coffin_display_handles_aux:nnnn
                  \l__coffin_internal_tl
              }
          }
      }
  }
\cs_new_protected:Npn \__coffin_display_handles_aux:nnnn #1#2#3#4
  {
    \__coffin_display_attach:Nnnnn
      \l__coffin_display_coord_coffin {#1} {#2}
      { #3 \l__coffin_display_offset_dim }
      { #4 \l__coffin_display_offset_dim }
  }
\cs_generate_variant:Nn \coffin_display_handles:Nn { c }
\cs_new_protected:Npn \__coffin_display_attach:Nnnnn #1#2#3#4#5
  {
    \__coffin_calculate_intersection:Nnn #1 {#2} {#3}
    \dim_set:Nn \l__coffin_x_prime_dim { \l__coffin_x_dim }
    \dim_set:Nn \l__coffin_y_prime_dim { \l__coffin_y_dim }
    \dim_set:Nn \l__coffin_offset_x_dim
      { \l__coffin_display_x_dim - \l__coffin_x_prime_dim + #4 }
    \dim_set:Nn \l__coffin_offset_y_dim
      { \l__coffin_display_y_dim - \l__coffin_y_prime_dim + #5 }
    \hbox_set:Nn \l__coffin_aligned_coffin
      {
        \box_use:N \l__coffin_display_coffin
        \tex_kern:D -\box_wd:N \l__coffin_display_coffin
        \tex_kern:D \l__coffin_offset_x_dim
        \box_move_up:nn { \l__coffin_offset_y_dim } { \box_use:N #1 }
      }
    \box_set_ht:Nn \l__coffin_aligned_coffin
      { \box_ht:N \l__coffin_display_coffin }
    \box_set_dp:Nn \l__coffin_aligned_coffin
      { \box_dp:N \l__coffin_display_coffin }
    \box_set_wd:Nn \l__coffin_aligned_coffin
      { \box_wd:N \l__coffin_display_coffin }
    \box_set_eq:NN \l__coffin_display_coffin \l__coffin_aligned_coffin
  }
\cs_new_protected:Npn \coffin_show_structure:N #1
  {
    \__coffin_if_exist:NT #1
      {
        \__msg_show_variable:Nnn #1 { coffins }
          {
            \prop_map_function:cN
              { l__coffin_poles_ \__int_value:w #1 _prop }
              \__msg_show_item_unbraced:nn
          }
      }
  }
\cs_generate_variant:Nn \coffin_show_structure:N { c }
\__msg_kernel_new:nnnn { kernel } { no-pole-intersection }
  { No~intersection~between~coffin~poles. }
  {
    \c_msg_coding_error_text_tl
    LaTeX~was~asked~to~find~the~intersection~between~two~poles,~
    but~they~do~not~have~a~unique~meeting~point:~
    the~value~(0~pt,~0~pt)~will~be~used.
  }
\__msg_kernel_new:nnnn { kernel } { unknown-coffin }
  { Unknown~coffin~'#1'. }
  { The~coffin~'#1'~was~never~defined. }
\__msg_kernel_new:nnnn { kernel } { unknown-coffin-pole }
  { Pole~'#1'~unknown~for~coffin~'#2'. }
  {
    \c_msg_coding_error_text_tl
    LaTeX~was~asked~to~find~a~typesetting~pole~for~a~coffin,~
    but~either~the~coffin~does~not~exist~or~the~pole~name~is~wrong.
  }
\__msg_kernel_new:nnn { kernel } { show-coffins }
  {
    Size~of~coffin~\token_to_str:N #1 : \\
    > ~ ht~=~\dim_use:N \box_ht:N #1 \\
    > ~ dp~=~\dim_use:N \box_dp:N #1 \\
    > ~ wd~=~\dim_use:N \box_wd:N #1 \\
    Poles~of~coffin~\token_to_str:N #1 :
  }
%% 
%%
%% End of file `l3coffins.sty'.
