diff options
author | Karl Berry <karl@freefriends.org> | 2012-08-21 22:32:05 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2012-08-21 22:32:05 +0000 |
commit | 9adf8e355a84312cf403250df2e41e11b893e687 (patch) | |
tree | 4272e0790b8f315ebb30a2868b06fc18df140ff5 /Master/texmf-dist/tex | |
parent | 7b9f0907404079d0b41248fc94a2308340f2e402 (diff) |
new latex package endiagram (21aug12)
git-svn-id: svn://tug.org/texlive/trunk@27489 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/latex/endiagram/endiagram.sty | 1540 |
1 files changed, 1540 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/endiagram/endiagram.sty b/Master/texmf-dist/tex/latex/endiagram/endiagram.sty new file mode 100644 index 00000000000..bea29774539 --- /dev/null +++ b/Master/texmf-dist/tex/latex/endiagram/endiagram.sty @@ -0,0 +1,1540 @@ +% -------------------------------------------------------------------------- +% the ENdiagram package +% +% easy creation of potential energy curve diagrams +% +% -------------------------------------------------------------------------- +% Clemens Niederberger +% Web: https://www.bitbucket.org/cgnieder/endiagram +% E-Mail: contact@mychemistry.eu +% -------------------------------------------------------------------------- +% If you have any ideas, questions, suggestions or bugs to report, please +% feel free to contact me. +% -------------------------------------------------------------------------- +% Copyright 2012 Clemens Niederberger +% +% This work may be distributed and/or modified under the +% conditions of the LaTeX Project Public License, either version 1.3 +% 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.3 or later is part of all distributions of LaTeX +% version 2005/12/01 or later. +% +% This work has the LPPL maintenance status `maintained'. +% +% The Current Maintainer of this work is Clemens Niederberger. +% +% This work consists of the files endiagram.sty, endiagram_en.tex, +% README and the derived file endiagram_en.pdf. +% -------------------------------------------------------------------------- +\RequirePackage{ expl3 , xparse , l3keys2e , tikz , siunitx } +\usetikzlibrary{calc} +\ProvidesExplPackage + {endiagram} + {2012/08/20} + {0.1a} + {Easy creation of potential energy curve diagrams} + +% --------------------------------------------------------------------------- % +% error and warning messages +\msg_set:nnnn { ENdiagram } { points-missing } + { + You~need~at~least~three~values~for~drawing~the~energy~curve~ + \msg_line_context: + } + { + You~need~at~least~three~values~for~drawing~the~energy~curve~ + \msg_line_context: + } + +\msg_set:nnnn { ENdiagram } { ShowEa } + { Wrong~argument~syntax.~ \msg_line_context: } + { Wrong~argument~syntax.~ \msg_line_context: } + +\msg_set:nnnn { ENdiagram } { MakeOrigin } + { + You~can't~use~\token_to_str:N \ENcurve \c_space_tl after~ + \token_to_str:N \MakeOrigin \c_space_tl \msg_line_context: + } + { + You~can't~use~\token_to_str:N \ENcurve \c_space_tl after~ + \token_to_str:N \MakeOrigin \c_space_tl \msg_line_context: + } + +% --------------------------------------------------------------------------- % +% tikz helper functions +\cs_new_nopar:Npn \ENdiagram_node:n #1 + { \node [ #1 ] } +\cs_generate_variant:Nn \ENdiagram_node:n { o,f,x } + +\cs_new_nopar:Npn \ENdiagram_draw:n #1 + { \draw [ #1 ] } +\cs_generate_variant:Nn \ENdiagram_draw:n { o,f,x } + +\cs_new_nopar:Npn \ENdiagram_draw:nn #1#2 + { \draw [ #1 ] #2 ; } +\cs_generate_variant:Nn \ENdiagram_draw:nn + { no,nf,nx,oo,of,ox,fn,fo,ff,fx,xn,xo,xf,xx } + +\cs_new_nopar:Npn \ENdiagram_tikz:n #1 + { \tikz [ #1 ] } +\cs_generate_variant:Nn \ENdiagram_tikz:n { o,f,x } + +\cs_new_nopar:Npn \ENdiagram_tikz:nn #1#2 + { \tikz [ #1 ] { #2 } } +\cs_generate_variant:Nn \ENdiagram_tikz:nn + { no,nf,nx,oo,of,ox,fn,fo,ff,fx,xn,xo,xf,xx } + +\cs_new_nopar:Npn \ENdiagram_start_tikzpicture:n #1 + { \tikzpicture [ #1 ] } +\cs_generate_variant:Nn \ENdiagram_start_tikzpicture:n { o,f,x } + +\cs_new_eq:NN \ENdiagram_end_tikzpicture: \endtikzpicture + +% --------------------------------------------------------------------------- % +\cs_if_exist:NF \l_tmpa_fp { \fp_new:N \l_tmpa_fp } +\cs_if_exist:NF \l_tmpb_fp { \fp_new:N \l_tmpb_fp } +\cs_if_exist:NF \l_tmpc_fp { \fp_new:N \l_tmpc_fp } +\cs_if_exist:NF \g_tmpa_fp { \fp_new:N \g_tmpa_fp } + +% --------------------------------------------------------------------------- % +% draw the curve +\clist_new:N \l_ENdiagram_points_clist +\prop_new:N \l_ENdiagram_points_prop +\int_new:N \l_ENdiagram_points_int +\int_zero:N \l_ENdiagram_points_int + +\int_new:N \g_ENdiagram_curve_int +\int_gzero:N \g_ENdiagram_curve_int + +\int_new:N \g_ENdiagram_points_max_int + +\int_new:N \l_ENdiagram_points_counter_int +\int_set:Nn \l_ENdiagram_points_counter_int { 1 } + +\tl_new:N \l_ENdiagram_draw_curve_tl +\tl_new:N \l_ENdiagram_curve_tikz_tl + +\tl_new:N \l_ENdiagram_curve_looseness_tl +\tl_set:Nn \l_ENdiagram_curve_looseness_tl { .5 } + +\tl_new:N \l_ENdiagram_points_step_tl +\tl_set:Nn \l_ENdiagram_points_step_tl { 2 } +\tl_new:N \l_ENdiagram_points_step_default_tl +\tl_set_eq:NN \l_ENdiagram_points_step_default_tl \l_ENdiagram_points_step_tl + +\fp_new:N \g_ENdiagram_y_min_fp +\fp_gzero:N \g_ENdiagram_y_min_fp +\fp_new:N \g_ENdiagram_y_max_fp +\fp_gzero:N \g_ENdiagram_y_max_fp + +\fp_new:N \g_ENdiagram_x_min_fp +\fp_gzero:N \g_ENdiagram_x_min_fp +\fp_new:N \g_ENdiagram_x_max_fp +\fp_gzero:N \g_ENdiagram_x_max_fp + +\bool_new:N \l_ENdiagram_debug_bool +\bool_new:N \l_ENdiagram_curve_minima_bool + +\keys_define:nn { ENdiagram / ENcurve } + { + step .tl_set:N = \l_ENdiagram_points_step_tl , + looseness .tl_set:N = \l_ENdiagram_curve_looseness_tl , + tikz .tl_set:N = \l_ENdiagram_curve_tikz_tl , + minima .bool_set:N = \l_ENdiagram_curve_minima_bool + } + +\cs_new_nopar:Npn \ENdiagram_determine_yaxis_length:n #1 + { + \fp_compare:nNnT { #1 } < { \g_ENdiagram_y_min_fp } + { \fp_gset:Nn \g_ENdiagram_y_min_fp { #1 } } + \fp_compare:nNnT { #1 } > { \g_ENdiagram_y_max_fp } + { \fp_gset:Nn \g_ENdiagram_y_max_fp { #1 } } + } + +\cs_new_nopar:Npn \ENdiagram_determine_xaxis_length: + { + \fp_gset:Nn \g_ENdiagram_x_max_fp { \int_to_arabic:n { \g_ENdiagram_points_max_int } } + \fp_gsub:Nn \g_ENdiagram_x_max_fp { 1 } + \exp_args:NNo \fp_gmul:Nn \g_ENdiagram_x_max_fp { \l_ENdiagram_points_step_tl } + } + +\NewDocumentCommand \ENdiagram_curve:w { o m } + { + \bool_if:NT \l_ENdiagram_origin_made_bool + { \msg_error:nn { ENdiagram } { MakeOrigin } } + \int_gincr:N \g_ENdiagram_curve_int + \tl_set_eq:NN \l_ENdiagram_points_step_tl \l_ENdiagram_points_step_default_tl + \IfNoValueF { #1 } { \keys_set:nn { ENdiagram / ENcurve } { #1 } } + \clist_clear:N \l_ENdiagram_points_clist + \tl_clear:N \l_ENdiagram_draw_curve_tl + \int_set:Nn \l_ENdiagram_points_counter_int { 1 } + \clist_map_inline:nn { #2 } + { + \fp_set:Nn \l_tmpa_tl { \int_to_arabic:n { \l_ENdiagram_points_int } } + \fp_mul:Nn \l_tmpa_tl { \l_ENdiagram_points_step_tl } + \tl_if_in:nnTF { ##1 } { [ } + { + \exp_args:Nfx \ENdiagram_save_points:nnnn + { \int_use:N \l_ENdiagram_points_int } + { \fp_to_tl:N \l_tmpa_tl } ##1 + } + { + \exp_args:Nfx \ENdiagram_save_points:nnnn + { \int_use:N \l_ENdiagram_points_int } + { \fp_to_tl:N \l_tmpa_tl } { ##1 } [ 0 ] + } + } + \int_zero:N \l_ENdiagram_points_int + \int_gset:Nn \g_ENdiagram_points_max_int + { \clist_length:N \l_ENdiagram_points_clist } + \int_compare:nT { \g_ENdiagram_points_max_int < 3 } + { \msg_error:nn { ENdiagram } { points-missing } } + \clist_map_inline:Nn \l_ENdiagram_points_clist + { + \int_compare:nT { \l_ENdiagram_points_counter_int = 1 } + { + \fp_gset:Nn \g_ENdiagram_y_min_fp { ##1 } + \bool_if:NT \l_ENdiagram_curve_minima_bool + { + \tl_put_right:Nn \l_ENdiagram_draw_curve_tl + { ($(-.5,##1)+(0,.2)$) to [bend~right] } + } + } + \ENdiagram_determine_yaxis_length:n { ##1 } + \ENdiagram_determine_xaxis_length: + \fp_set:Nn \l_tmpa_tl { \int_to_arabic:n { \l_ENdiagram_points_counter_int } } + \fp_sub:Nn \l_tmpa_tl { 1 } + \exp_args:NNx \prop_get:NnN \l_ENdiagram_points_prop + { \fp_to_tl:N \l_tmpa_tl } \l_tmpb_tl + \tl_put_right:Nx \l_ENdiagram_draw_curve_tl + { + ($ + { + \l_tmpb_tl + } + *(1,0)+(0,##1) + $) + node[inner~sep=0] + ( + N \int_to_arabic:n { \g_ENdiagram_curve_int } - + \int_to_arabic:n { \l_ENdiagram_points_counter_int } + ) {} + } + \bool_if:NT \l_ENdiagram_debug_bool + { + \tl_put_right:Nx \l_ENdiagram_draw_curve_tl + { + node[anchor=north~west,font={\exp_not:N \tiny},inner~sep=0,color=black,fill=yellow!20] + { + N \int_to_arabic:n { \g_ENdiagram_curve_int } - + \int_to_arabic:n { \l_ENdiagram_points_counter_int } + } + node[inner~sep=0,above,color=red,font={\exp_not:N \tiny}] + {(\l_tmpb_tl,##1)} + } + } + \int_compare:nT { \l_ENdiagram_points_counter_int < \g_ENdiagram_points_max_int } + { + \tl_put_right:Nn \l_ENdiagram_draw_curve_tl { to } + } + \int_compare:nT { \l_ENdiagram_points_counter_int = \g_ENdiagram_points_max_int } + { + \bool_if:NT \l_ENdiagram_curve_minima_bool + { + \tl_put_right:Nx \l_ENdiagram_draw_curve_tl + { + to [bend~right] + ($ + { + \l_ENdiagram_points_step_tl * + (\int_to_arabic:n { \l_ENdiagram_points_counter_int } - 1 ) + } + *(1,0)+(0,##1)+(.5,.2) + $) + } + } + } + \int_incr:N \l_ENdiagram_points_counter_int + } + + \ENdiagram_draw:xo + { + \l_ENdiagram_curve_tikz_tl, + out=0,in=180, + looseness=\l_ENdiagram_curve_looseness_tl + } + { \l_ENdiagram_draw_curve_tl } + \tl_clear:N \l_ENdiagram_curve_tikz_tl + } +\cs_generate_variant:Nn \tl_put_right:Nn { Nx } + +\cs_new_nopar:Npn \ENdiagram_save_points:nnnn #1#2#3[#4] + { + \fp_set:Nn \l_tmpa_tl { #2 } + \fp_add:Nn \l_tmpa_tl { #4 } + \clist_put_right:Nn \l_ENdiagram_points_clist { #3 } + \exp_args:NNox \prop_put:Nnn \l_ENdiagram_points_prop { #1 } { \fp_to_tl:N \l_tmpa_tl } + \int_incr:N \l_ENdiagram_points_int + } + +% --------------------------------------------------------------------------- % +% show the energy levels +\int_new:N \l_ENdiagram_niveau_counter_int +\int_set:Nn \l_ENdiagram_niveau_counter_int { 1 } + +\tl_new:N \l_ENdiagram_niveau_tikz_tl + +\tl_new:N \l_ENdiagram_niveau_length_tl +\tl_set:Nn \l_ENdiagram_niveau_length_tl { 1 } + +\tl_new:N \l_ENdiagram_niveau_shift_tl +\tl_set:Nn \l_ENdiagram_niveau_shift_tl { 0 } + +\bool_new:N \l_ENdiagram_niveau_pick_bool +\clist_new:N \l_ENdiagram_niveau_clist + +\keys_define:nn { ENdiagram / ShowNiveaus } + { + tikz .tl_set:N = \l_ENdiagram_niveau_tikz_tl , + length .tl_set:N = \l_ENdiagram_niveau_length_tl , + shift .tl_set:N = \l_ENdiagram_niveau_shift_tl , + niveau .code:n = + { + \bool_set_true:N \l_ENdiagram_niveau_pick_bool + \clist_clear:N \l_ENdiagram_niveau_clist + \clist_set:Nn \l_ENdiagram_niveau_clist { #1 } + } + } + +\NewDocumentCommand \ENdiagram_show_niveaus:w { o } + { + \group_begin: + \IfNoValueF { #1 } { \keys_set:nn { ENdiagram / ShowNiveaus } { #1 } } + \bool_if:NTF \l_ENdiagram_niveau_pick_bool + { + \clist_map_inline:Nn \l_ENdiagram_niveau_clist + { + \ENdiagram_draw:xn { \l_ENdiagram_niveau_tikz_tl } + { + (##1) ++ (\l_ENdiagram_niveau_shift_tl,0) + ++(-.5*\l_ENdiagram_niveau_length_tl,0) -- ++(\l_ENdiagram_niveau_length_tl,0) + } + } + } + { + \int_do_until:nn { \l_ENdiagram_niveau_counter_int > \g_ENdiagram_points_max_int } + { + \ENdiagram_draw:xn { \l_ENdiagram_niveau_tikz_tl } + { + ( + N + \int_to_arabic:n { \g_ENdiagram_curve_int } + - + \int_to_arabic:n { \l_ENdiagram_niveau_counter_int } + ) + ++ (\l_ENdiagram_niveau_shift_tl,0) + ++(-.5*\l_ENdiagram_niveau_length_tl,0) -- ++(\l_ENdiagram_niveau_length_tl,0) + } + \int_incr:N \l_ENdiagram_niveau_counter_int + } + } + \group_end: + } + +% --------------------------------------------------------------------------- % +% show the energy gain +\bool_new:N \l_ENdiagram_show_gain_right_bool +\bool_set_false:N \l_ENdiagram_show_gain_right_bool +\bool_new:N \l_ENdiagram_gain_label_bool +\bool_set_false:N \l_ENdiagram_gain_label_bool +\bool_new:N \l_ENdiagram_gain_own_label_bool +\bool_set_false:N \l_ENdiagram_gain_own_label_bool +\bool_new:N \l_ENdiagram_gain_connect_from_niveau_bool +\bool_set_false:N \l_ENdiagram_gain_connect_from_niveau_bool + +\tl_new:N \l_ENdiagram_gain_label_text_tl +\tl_new:N \l_ENdiagram_gain_label_side_tl +\tl_set:Nn \l_ENdiagram_gain_label_side_tl { right } +\tl_new:N \l_ENdiagram_gain_label_pos_tl +\tl_set:Nn \l_ENdiagram_gain_label_pos_tl { .5 } +\tl_new:N \l_ENdiagram_gain_label_tikz_tl +\tl_new:N \l_ENdiagram_gain_tikz_tl +\tl_set:Nn \l_ENdiagram_gain_tikz_tl { <-> } +\tl_new:N \l_ENdiagram_gain_connect_tikz_tl +\tl_set:Nn \l_ENdiagram_gain_connect_tikz_tl { dashed,help~lines } +\tl_new:N \l_ENdiagram_gain_x_value_tl +\tl_new:N \l_ENdiagram_gain_offset_tl +\tl_set:Nn \l_ENdiagram_gain_offset_tl { 0 } +\tl_new:N \g_ENdiagram_gain_offset_tl +\tl_gset:Nn \g_ENdiagram_gain_offset_tl { 0 } +\tl_new:N \l_ENdiagram_gain_value_tl + +\keys_define:nn { ENdiagram / ShowGain } + { + tikz .tl_set:N = \l_ENdiagram_gain_tikz_tl , + connect .tl_set:N = \l_ENdiagram_gain_connect_tikz_tl , + connect-from-line .bool_set:N = \l_ENdiagram_gain_connect_from_niveau_bool , + connect-from-line .default:n = true , + offset .tl_set:N = \l_ENdiagram_gain_offset_tl , + label .code:n = + { + \tl_if_eq:nnTF { true } { #1 } + { \bool_set_true:N \l_ENdiagram_gain_label_bool } + { + \tl_if_eq:nnF { false } { #1 } + { + \bool_set_true:N \l_ENdiagram_gain_label_bool + \bool_set_true:N \l_ENdiagram_gain_own_label_bool + \tl_set:Nn \l_ENdiagram_gain_label_text_tl { #1 } + } + } + } , + label .default:n = true , + label-side .choice: , + label-side / right .code:n = + { \tl_set:Nn \l_ENdiagram_gain_label_side_tl { right } } , + label-side / left .code:n = + { \tl_set:Nn \l_ENdiagram_gain_label_side_tl { left } } , + label-pos .tl_set:N = \l_ENdiagram_gain_label_pos_tl , + label-tikz .tl_set:N = \l_ENdiagram_gain_label_tikz_tl + } + +\NewDocumentCommand \ENdiagram_show_gain:w { o } + { + \bool_set_true:N \l_ENdiagram_show_gain_right_bool + \group_begin: + \IfNoValueF { #1 } { \keys_set:nn { ENdiagram / ShowGain } { #1 } } + \fp_compare:nNnT { \g_ENdiagram_gain_offset_tl } < { \l_ENdiagram_gain_offset_tl } + { \tl_gset_eq:NN \g_ENdiagram_gain_offset_tl \l_ENdiagram_gain_offset_tl } + \tl_set:Nx \l_ENdiagram_gain_x_value_tl + { \int_to_arabic:n { \int_eval:n { \g_ENdiagram_points_max_int - 1} } } + \ENdiagram_draw:xn { \l_ENdiagram_gain_tikz_tl } + { + let \p1 = (N\int_to_arabic:n { \g_ENdiagram_curve_int }-1) , + \p2 = (N\int_to_arabic:n { \g_ENdiagram_curve_int }-\int_to_arabic:n { \g_ENdiagram_points_max_int }) + in + ($\l_ENdiagram_points_step_tl*(\l_ENdiagram_gain_x_value_tl,0)+(\l_ENdiagram_gain_offset_tl+1,\y1)$) + -- + ($\l_ENdiagram_points_step_tl*(\l_ENdiagram_gain_x_value_tl,0)+(\l_ENdiagram_gain_offset_tl+1,\y2)$) + node[pos=0,inner~sep=0] (gain-start\int_to_arabic:n { \g_ENdiagram_curve_int }) {} + node[pos=1,inner~sep=0] (gain-end\int_to_arabic:n { \g_ENdiagram_curve_int }) {} + } + \fp_set:Nn \l_tmpa_tl + { \clist_item:Nn \l_ENdiagram_points_clist { 1 } } + \fp_set:Nn \l_tmpb_tl + { \clist_item:Nn \l_ENdiagram_points_clist { \g_ENdiagram_points_max_int } } +% \fp_sub:Nn \l_tmpb_tl { 1 } + \fp_set:Nn \l_tmpc_tl + { + \l_ENdiagram_gain_x_value_tl * \l_ENdiagram_points_step_tl + + \l_ENdiagram_gain_offset_tl + 1 + } + \bool_if:NT \l_ENdiagram_debug_bool + { + \ENdiagram_draw:nn {font=\tiny,inner~sep=0} + { + let \p1 = ( gain-start\int_to_arabic:n { \g_ENdiagram_curve_int } ) , + \p2 = ( gain-end\int_to_arabic:n { \g_ENdiagram_curve_int } ) + in + node[right=2pt,fill=yellow!10] + at ( \p1 ) + { gain-start\int_to_arabic:n { \g_ENdiagram_curve_int } } + node[right=2pt,fill=yellow!10] + at ( \p2 ) + { gain-end\int_to_arabic:n { \g_ENdiagram_curve_int } } + node[above~right,red] at (\p1) {(\fp_to_tl:N \l_tmpc_tl,\fp_to_tl:N \l_tmpa_tl)} + node[above~right,red] at (\p2) {(\fp_to_tl:N \l_tmpc_tl,\fp_to_tl:N \l_tmpb_tl)} + } + } + \bool_if:NT \l_ENdiagram_gain_label_bool + { + \bool_if:NF \l_ENdiagram_gain_own_label_bool + { + \bool_if:nTF + { \l_ENdiagram_energy_unit_bool && \l_ENdiagram_calculate_bool } + { + \fp_set:Nn \l_tmpb_fp { (\l_tmpb_tl - \l_tmpa_tl) * \l_ENdiagram_energy_step_tl } + \bool_if:NTF \l_ENdiagram_energy_round_places_bool + { + \fp_round_places:Nn \l_tmpb_fp + { \l_ENdiagram_energy_round_tl } + } + { + \fp_round_figures:Nn \l_tmpb_fp + { \l_ENdiagram_energy_round_tl } + } + \tl_set:Nn \l_ENdiagram_gain_value_tl + { + = \exp_args:Noo \SI + { \fp_to_tl:N \l_tmpb_fp } + { \l_ENdiagram_energy_unit_tl } + } + } + { + \fp_compare:nNnTF { \l_tmpa_tl } > { \l_tmpb_tl } + { \tl_set:Nn \l_ENdiagram_gain_value_tl { < 0 } } + { \tl_set:Nn \l_ENdiagram_gain_value_tl { > 0 } } + } + \tl_set:Nn \l_ENdiagram_gain_label_text_tl { $\Delta H \l_ENdiagram_gain_value_tl$ } + } + \ENdiagram_draw:nx {} + { + ($ + (gain-end\int_to_arabic:n { \g_ENdiagram_curve_int }) + !\l_ENdiagram_gain_label_pos_tl! + (gain-start\int_to_arabic:n { \g_ENdiagram_curve_int })$) + node[\l_ENdiagram_gain_label_side_tl,\l_ENdiagram_gain_label_tikz_tl] + { \exp_not:N \l_ENdiagram_gain_label_text_tl } + } + } + \bool_if:NTF \l_ENdiagram_gain_connect_from_niveau_bool + { + \ENdiagram_draw:xf { \l_ENdiagram_gain_connect_tikz_tl } + { + let \p1 = (N\int_to_arabic:n { \g_ENdiagram_curve_int }-1) , + \p2 = (N\int_to_arabic:n { \g_ENdiagram_curve_int }-\int_to_arabic:n { \g_ENdiagram_points_max_int }) + in + (gain-end\int_to_arabic:n { \g_ENdiagram_curve_int }) ++ (.5,0) -- ($(\p2)+(.5*\l_ENdiagram_niveau_length_tl,0)$) + (gain-start\int_to_arabic:n { \g_ENdiagram_curve_int }) ++ (.5,0) -- ($(\p1)+(.5*\l_ENdiagram_niveau_length_tl,0)$) + } + } + { + \ENdiagram_draw:xf { \l_ENdiagram_gain_connect_tikz_tl } + { + let \p1 = (N\int_to_arabic:n { \g_ENdiagram_curve_int }-1) , + \p2 = (N\int_to_arabic:n { \g_ENdiagram_curve_int }-\int_to_arabic:n { \g_ENdiagram_points_max_int }) + in + (gain-end\int_to_arabic:n { \g_ENdiagram_curve_int }) ++ (.5,0) -- (\p2) + (gain-start\int_to_arabic:n { \g_ENdiagram_curve_int }) ++ (.5,0) -- (\p1) + } + } + \group_end: + } + +% --------------------------------------------------------------------------- % +% show the activation energy +\bool_new:N \l_ENdiagram_ea_all_bool +\bool_new:N \l_ENdiagram_ea_coordinates_bool +\bool_new:N \l_ENdiagram_ea_coordinates_points_bool +\bool_new:N \l_ENdiagram_ea_label_bool +\bool_new:N \l_ENdiagram_ea_own_label_bool + +\int_new:N \g_ENdiagram_ea_int +\int_gzero:N \g_ENdiagram_ea_int +\int_new:N \l_ENdiagram_ea_count_int +\int_zero:N \l_ENdiagram_ea_count_int + +\tl_new:N \l_ENdiagram_ea_tikz_tl +\tl_set:Nn \l_ENdiagram_ea_tikz_tl { <-> } +\tl_new:N \l_ENdiagram_ea_connect_tikz_tl +\tl_set:Nn \l_ENdiagram_ea_connect_tikz_tl { dashed, help~lines } +\tl_new:N \l_ENdiagram_ea_label_text_tl +\tl_set_rescan:Nnn \l_ENdiagram_ea_label_text_tl + { \char_set_catcode_math_subscript:N \_ } { $E_{\mathrm{a}}$ } +\tl_new:N \l_ENdiagram_ea_value_tl +\tl_new:N \l_ENdiagram_ea_label_tikz_tl +\tl_new:N \l_ENdiagram_ea_label_side_tl +\tl_set:Nn \l_ENdiagram_ea_label_side_tl { right } +\tl_new:N \l_ENdiagram_ea_label_pos_tl +\tl_set:Nn \l_ENdiagram_ea_label_pos_tl { .5} +\tl_new:N \l_ENdiagram_ea_start_node_tl +\tl_new:N \l_ENdiagram_ea_end_node_tl + +\fp_new:N \l_ENdiagram_ea_connect_start_fp +\fp_new:N \l_ENdiagram_ea_connect_end_fp + +\keys_define:nn { ENdiagram / ShowEa } + { + max .choice: , + max / all .code:n = \bool_set_true:N \l_ENdiagram_ea_all_bool , + max / first .code:n = \bool_set_false:N \l_ENdiagram_ea_all_bool , + tikz .tl_set:N = \l_ENdiagram_ea_tikz_tl , + connect .tl_set:N = \l_ENdiagram_ea_connect_tikz_tl , + from .code:n = + { + \bool_set_true:N \l_ENdiagram_ea_coordinates_bool + \ENdiagram_detect_ea:n { #1 } + } , + label .code:n = + { + \tl_if_eq:nnTF { true } { #1 } + { \bool_set_true:N \l_ENdiagram_ea_label_bool } + { + \tl_if_eq:nnF { false } { #1 } + { + \bool_set_true:N \l_ENdiagram_ea_own_label_bool + \bool_set_true:N \l_ENdiagram_ea_label_bool + \tl_set:Nn \l_ENdiagram_ea_label_text_tl { #1 } + } + } + } , + label .default:n = true , + label-side .choice: , + label-side / right .code:n = + { \tl_set:Nn \l_ENdiagram_ea_label_side_tl { right } } , + label-side / left .code:n = + { \tl_set:Nn \l_ENdiagram_ea_label_side_tl { left } } , + label-pos .tl_set:N = \l_ENdiagram_ea_label_pos_tl , + label-tikz .tl_set:N = \l_ENdiagram_ea_label_tikz_tl + } + +\cs_new_nopar:Npn \ENdiagram_detect_ea:n #1 + { + % remember blanks + \tl_set:Nn \l_tmpa_tl { #1 } + \tl_replace_all:Nnn \l_tmpa_tl { ~ } { @@@ } + \exp_after:wN \ENdiagram_detect_ea_auxi:nn \l_tmpa_tl \q_nil + } + +\cs_new_nopar:Npn \ENdiagram_detect_ea_auxi:nn (#1) #2 \q_nil + { + % recover blanks in node #1 + \tl_set:Nn \l_tmpa_tl { #1 } + \tl_replace_all:Nnn \l_tmpa_tl { @@@ } { ~ } + \tl_set_eq:NN \l_ENdiagram_ea_start_node_tl \l_tmpa_tl + \ENdiagram_detect_ea_auxii:nn #2 + } + +\cs_new_nopar:Npn \ENdiagram_detect_ea_auxii:nn #1 (#2) + { + % recover blanks in node #2 + \tl_set:Nn \l_tmpa_tl { #2 } + \tl_set:Nn \l_tmpb_tl { #1 } + \tl_replace_all:Nnn \l_tmpa_tl { @@@ } { ~ } + \tl_set_eq:NN \l_ENdiagram_ea_end_node_tl \l_tmpa_tl + % ignore blanks in between and test for right syntax + \tl_remove_all:Nn \l_tmpb_tl { @@@ } + \exp_args:No \tl_if_eq:nnF { \l_tmpb_tl } { to } + { \msg_error:nn { ENdiagram } { ShowEa } } + + } + +\NewDocumentCommand \ENdiagram_show_ea:w { o } + { + \int_gincr:N \g_ENdiagram_ea_int + \group_begin: + \IfNoValueF { #1 } { \keys_set:nn { ENdiagram / ShowEa } { #1 } } + \bool_if:NTF \l_ENdiagram_ea_coordinates_bool + { + \ENdiagram_draw:xn { \l_ENdiagram_ea_tikz_tl } + { + ( \l_ENdiagram_ea_end_node_tl |- \l_ENdiagram_ea_start_node_tl ) + -- + ( \l_ENdiagram_ea_end_node_tl ) + } + \bool_if:NT \l_ENdiagram_ea_label_bool + { + \bool_if:nT + { + \l_ENdiagram_energy_unit_bool && + \l_ENdiagram_calculate_bool && + !\l_ENdiagram_ea_own_label_bool + } + { + % determine length of Ea-line + \ENdiagram_draw:nn { } + { + let \p1 = (\l_ENdiagram_ea_start_node_tl), + \p2 = (\l_ENdiagram_ea_end_node_tl) + in + node at (\p2) { \dim_gset:Nn \g_tmpa_dim { \y2 - \y1 } } + } + % convert length of Ea-line into energy value + \fp_set:Nn \l_tmpb_fp { \dim_to_fp:Nn { 1cm } } + \fp_set:Nn \l_tmpa_fp + { \dim_to_fp:n { \g_tmpa_dim } / \l_tmpb_fp * \l_ENdiagram_energy_step_tl } + \bool_if:NTF \l_ENdiagram_energy_round_places_bool + { + \fp_round_places:Nn \l_tmpa_fp + { \l_ENdiagram_energy_round_tl } + } + { + \fp_round_figures:Nn \l_tmpa_fp + { \l_ENdiagram_energy_round_tl } + } + \tl_set:Nn \l_ENdiagram_ea_value_tl + { + ~ = ~ \exp_args:Noo \SI + { \fp_to_tl:N \l_tmpa_fp } + { \l_ENdiagram_energy_unit_tl } + } + } + \ENdiagram_draw:xn + { \l_ENdiagram_ea_label_tikz_tl } + { + node[\l_ENdiagram_ea_label_side_tl] at + ($ + (\l_ENdiagram_ea_end_node_tl) + !\l_ENdiagram_ea_label_pos_tl! + (\l_ENdiagram_ea_end_node_tl |- \l_ENdiagram_ea_start_node_tl) + $) + { \l_ENdiagram_ea_label_text_tl \l_ENdiagram_ea_value_tl } + } + } + \ENdiagram_draw:xn { \l_ENdiagram_ea_connect_tikz_tl } + { + ( \l_ENdiagram_ea_start_node_tl ) + -- + ( \l_ENdiagram_ea_end_node_tl |- \l_ENdiagram_ea_start_node_tl ) + node + ( + ea-end + \int_to_arabic:n { \g_ENdiagram_curve_int }- + \int_to_arabic:n { \g_ENdiagram_ea_int }- + 0 + ) {} + } + \bool_if:NT \l_ENdiagram_debug_bool + { + \ENdiagram_draw:nn { inner~sep=0,font=\tiny } + { + ( + ea-end + \int_to_arabic:n { \g_ENdiagram_curve_int }- + \int_to_arabic:n { \g_ENdiagram_ea_int }- + 0 + ) + node[below~right,fill=yellow!10] + { + ea-end + \int_to_arabic:n { \g_ENdiagram_curve_int }- + \int_to_arabic:n { \g_ENdiagram_ea_int }- + 0 + } + } + } + } + { + \int_do_until:nn + { \l_ENdiagram_ea_count_int >= \g_ENdiagram_points_max_int - 1 } + { + \fp_set:Nn \l_tmpa_tl + { + \clist_item:Nn \l_ENdiagram_points_clist + { \int_eval:n { \l_ENdiagram_ea_count_int + 1 } } + } + \fp_set:Nn \l_tmpb_tl + { + \clist_item:Nn \l_ENdiagram_points_clist + { \int_eval:n { \l_ENdiagram_ea_count_int + 2 } } + } + \fp_compare:nNnT { \l_tmpa_tl } < { \l_tmpb_tl } + { + \exp_args:NNf \prop_get:NnN \l_ENdiagram_points_prop + { \int_eval:n { \l_ENdiagram_ea_count_int + 1 } } \l_tmpc_tl + \fp_set:Nn \l_ENdiagram_ea_connect_end_fp { \l_tmpc_tl } + \exp_args:NNf \prop_get:NnN \l_ENdiagram_points_prop + { \int_eval:n { \l_ENdiagram_ea_count_int } } \l_tmpc_tl + \fp_set:Nn \l_ENdiagram_ea_connect_start_fp { \l_tmpc_tl } + \ENdiagram_draw:xn { \l_ENdiagram_ea_tikz_tl } + { + ( \fp_to_tl:N \l_ENdiagram_ea_connect_end_fp , \fp_to_tl:N \l_tmpa_tl ) + node + ( + ea-end + \int_to_arabic:n { \g_ENdiagram_curve_int }- + \int_to_arabic:n { \g_ENdiagram_ea_int }- + \int_to_arabic:n { \l_ENdiagram_ea_count_int } + ) { } + -- + ( \fp_to_tl:N \l_ENdiagram_ea_connect_end_fp , \fp_to_tl:N \l_tmpb_tl ) + } + \bool_if:NT \l_ENdiagram_ea_label_bool + { + \bool_if:nT + { + \l_ENdiagram_energy_unit_bool && + \l_ENdiagram_calculate_bool && + !\l_ENdiagram_ea_own_label_bool + } + { + \fp_set:Nn \l_tmpb_fp { \l_tmpb_tl } + \fp_sub:Nn \l_tmpb_fp { \l_tmpa_tl } + \fp_mul:Nn \l_tmpb_fp { \l_ENdiagram_energy_step_tl } + \tl_set:Nn \l_ENdiagram_ea_value_tl + { + ~ = ~ \exp_args:Noo \SI + { \fp_to_tl:N \l_tmpb_fp } + { \l_ENdiagram_energy_unit_tl } + } + } + \ENdiagram_draw:xn { \l_ENdiagram_ea_label_tikz_tl } + { + node[\l_ENdiagram_ea_label_side_tl] at + ($ + ( \fp_to_tl:N \l_ENdiagram_ea_connect_end_fp , \fp_to_tl:N \l_tmpa_tl ) + !\l_ENdiagram_ea_label_pos_tl! + ( \fp_to_tl:N \l_ENdiagram_ea_connect_end_fp , \fp_to_tl:N \l_tmpb_tl ) + $) + { \l_ENdiagram_ea_label_text_tl \l_ENdiagram_ea_value_tl } + } + } + \ENdiagram_draw:xn { \l_ENdiagram_ea_connect_tikz_tl } + { + ( \fp_to_tl:N \l_ENdiagram_ea_connect_end_fp , \fp_to_tl:N \l_tmpa_tl ) + -- + ++ + ( + \fp_to_tl:N \l_ENdiagram_ea_connect_start_fp + - + \fp_to_tl:N \l_ENdiagram_ea_connect_end_fp , 0 + ) + } + \bool_if:NT \l_ENdiagram_debug_bool + { + \ENdiagram_draw:nn { inner~sep=0,font=\tiny } + { + ( + ea-end + \int_to_arabic:n { \g_ENdiagram_curve_int }- + \int_to_arabic:n { \g_ENdiagram_ea_int }- + \int_to_arabic:n { \l_ENdiagram_ea_count_int } + ) + node[below~right,fill=yellow!10] + { + ea-end + \int_to_arabic:n { \g_ENdiagram_curve_int }- + \int_to_arabic:n { \g_ENdiagram_ea_int }- + \int_to_arabic:n { \l_ENdiagram_ea_count_int } + } + node[above~right,red] + { ( \fp_to_tl:N \l_ENdiagram_ea_connect_end_fp , \fp_to_tl:N \l_tmpa_tl ) } + } + } + \bool_if:NF \l_ENdiagram_ea_all_bool + { + % set count unreasonably high to ensure we're over + % \g_ENdiagram_points_max_int + \int_add:Nn \l_ENdiagram_ea_count_int { 1000 } + } + } + \int_incr:N \l_ENdiagram_ea_count_int + } + } + \group_end: + } + +% --------------------------------------------------------------------------- % +% add axis labels +\bool_new:N \l_ENdiagram_add_axis_yl_bool +\bool_set_true:N \l_ENdiagram_add_axis_yl_bool +\bool_new:N \l_ENdiagram_add_axis_yr_bool +\bool_new:N \l_ENdiagram_add_axis_x_bool + +\tl_new:N \l_ENdiagram_add_axis_connect_tl +\tl_set:Nn \l_ENdiagram_add_axis_connect_tl { dashed,help~lines } +\tl_new:N \l_ENdiagram_add_axis_font_tl + +\keys_define:nn { ENdiagram / AddAxisLabel } + { + axis .choice: , + axis / y-l .code:n = + { + \bool_set_true:N \l_ENdiagram_add_axis_yl_bool + \bool_set_false:N \l_ENdiagram_add_axis_yr_bool + \bool_set_false:N \l_ENdiagram_add_axis_x_bool + } , + axis / y-r .code:n = + { + \bool_set_false:N \l_ENdiagram_add_axis_yl_bool + \bool_set_true:N \l_ENdiagram_add_axis_yr_bool + \bool_set_false:N \l_ENdiagram_add_axis_x_bool + } , + axis / x .code:n = + { + \bool_set_false:N \l_ENdiagram_add_axis_yl_bool + \bool_set_false:N \l_ENdiagram_add_axis_yr_bool + \bool_set_true:N \l_ENdiagram_add_axis_x_bool + } , + connect .tl_set:N = \l_ENdiagram_add_axis_connect_tl , + font .tl_set:N = \l_ENdiagram_add_axis_font_tl + } + +\NewDocumentCommand \ENdiagram_add_axis_label:w { so > { \SplitList { ; } } m } + { + \ENdiagram_make_origin: + \group_begin: + \tl_clear:N \l_tmpa_tl + \tl_clear:N \l_tmpb_tl + \tl_clear:N \l_tmpc_tl + \IfNoValueF { #2 } { \keys_set:nn { ENdiagram / AddAxisLabel } { #2 } } + \IfBooleanTF { #1 } + { % list of "ticks" + \bool_if:NT \l_ENdiagram_add_axis_yl_bool + { \ENdiagram_add_axis_label_yl_ticks:n { #3 } } + \bool_if:NT \l_ENdiagram_add_axis_yr_bool + { \ENdiagram_add_axis_label_yr_ticks:n { #3 } } + \bool_if:NT \l_ENdiagram_add_axis_x_bool + { \ENdiagram_add_axis_label_x_ticks:n { #3 } } + } + { % list of points + \bool_if:NT \l_ENdiagram_add_axis_yl_bool + { \ENdiagram_add_axis_label_yl_points:n { #3 } } + \bool_if:NT \l_ENdiagram_add_axis_yr_bool + { \ENdiagram_add_axis_label_yr_points:n { #3 } } + \bool_if:NT \l_ENdiagram_add_axis_x_bool + { \ENdiagram_add_axis_label_x_points:n { #3 } } + } + \group_end: + } + +\cs_new_nopar:Npn \ENdiagram_add_axis_label_yl_ticks:n #1 + { + \tl_map_inline:nn { #1 } + { + \tl_if_in:nnTF { ##1 } { [ } + { + \group_begin: + \ENdiagram_get_tick_arg_and_label:w ##1 \q_stop + \fp_set:Nn \l_tmpb_fp { \l_tmpb_tl } + \bool_if:NT \l_ENdiagram_energy_bool + { + \fp_mul:Nn \l_tmpb_fp { \l_ENdiagram_energy_step_tl } + \fp_sub:Nn \l_tmpb_fp { \l_ENdiagram_energy_zero_tl } + \bool_if:NTF \l_ENdiagram_energy_round_places_bool + { + \fp_round_places:Nn \l_tmpb_fp + { \l_ENdiagram_energy_round_tl } + } + { + \fp_round_figures:Nn \l_tmpb_fp + { \l_ENdiagram_energy_round_tl } + } + \tl_set:Nn \l_tmpb_tl { \fp_to_tl:N \l_tmpb_fp } + } + \ENdiagram_draw:nx { } + { + let \exp_not:N \p1 = (origin-l) + in + ( \exp_not:N \x1 , \fp_to_tl:N \l_tmpa_fp ) -- ++ (-3pt,0) + node[left,font=\exp_not:o \l_ENdiagram_add_axis_font_tl,\l_tmpc_tl] + { \l_tmpb_tl } + } + \group_end: + } + { + \fp_set:Nn \l_tmpa_fp { ##1 } + \bool_if:NT \l_ENdiagram_energy_bool + { + \fp_mul:Nn \l_tmpa_fp { \l_ENdiagram_energy_step_tl } + \fp_sub:Nn \l_tmpa_fp { \l_ENdiagram_energy_zero_tl } + } + \ENdiagram_draw:nn { } + { + let \p1 = (origin-l) + in + ( \x1 , ##1 ) -- ++ (-3pt,0) + node[left,font=\l_ENdiagram_add_axis_font_tl] + { \fp_to_tl:N \l_tmpa_fp } + } + } + } + } + +% TODO: sollte Energie-Skala und Rundung beachten! +\cs_new_nopar:Npn \ENdiagram_add_axis_label_yr_ticks:n #1 + { + \tl_map_inline:nn { #1 } + { + \tl_if_in:nnTF { ##1 } { [ } + { + \group_begin: + \ENdiagram_get_tick_arg_and_label:w ##1 \q_stop + \ENdiagram_draw:nx { } + { + ( \fp_to_tl:N \g_ENdiagram_x_max_fp , \l_tmpa_tl ) -- ++ (3pt,0) + node[right,font=\exp_not:o \l_ENdiagram_add_axis_font_tl,\l_tmpc_tl] + { \l_tmpb_tl } + } + \group_end: + } + { + \ENdiagram_draw:nn { } + { + let \p1 = (origin-r) + in + ( \x1 , ##1 ) -- ++ (3pt,0) + node[right,font=\l_ENdiagram_add_axis_font_tl] { ##1 } + } + } + } + } + +\cs_new_nopar:Npn \ENdiagram_add_axis_label_x_ticks:n #1 + { + \tl_map_inline:nn { #1 } + { + \tl_if_in:nnTF { ##1 } { [ } + { + \group_begin: + \ENdiagram_get_tick_arg_and_label:w ##1 \q_stop + \ENdiagram_draw:nx { } + { + let \exp_not:N \p1 = (origin-l) + in + ( \l_tmpa_tl , \exp_not:N \y1 ) -- ++ (-3pt,0) + node[below,font=\exp_not:o \l_ENdiagram_add_axis_font_tl,\l_tmpc_tl] + { \l_tmpb_tl } + } + \group_end: + } + { + \ENdiagram_draw:nn { } + { + let \p1 = (origin-l) + in + ( ##1 , \y1 ) -- ++ (-3pt,0) + node[below,font=\l_ENdiagram_add_axis_font_tl] { ##1 } + } + } + } + } + +\cs_new_nopar:Npn \ENdiagram_add_axis_label_yl_points:n #1 + { + \tl_map_inline:nn { #1 } + { + \tl_if_in:nnTF { ##1 } { [ } + { + \group_begin: + \ENdiagram_get_tick_point_and_label:w ##1 \q_stop + \ENdiagram_draw:xn { \l_ENdiagram_add_axis_connect_tl } + { + (\l_tmpa_tl) -- (\l_tmpa_tl -| origin-l) + } + \ENdiagram_draw:nx { } + { + (\l_tmpa_tl -| origin-l) -- ++ (-3pt,0) + node[left,font=\exp_not:o \l_ENdiagram_add_axis_font_tl,\l_tmpc_tl] + { \l_tmpb_tl } + } + \group_end: + } + { + \group_begin: + \ENdiagram_get_tick_node:w ##1 \q_stop + \ENdiagram_draw:xn { \l_ENdiagram_add_axis_connect_tl } + { + (\l_tmpa_tl) -- (\l_tmpa_tl -| origin-l) + } + \ENdiagram_draw:nn { } + { + (\l_tmpa_tl -| origin-l) -- ++ (-3pt,0) + } + \group_end: + } + } + } + +\cs_new_nopar:Npn \ENdiagram_add_axis_label_yr_points:n #1 + { + \tl_map_inline:nn { #1 } + { + \tl_if_in:nnTF { ##1 } { [ } + { + \group_begin: + \ENdiagram_get_tick_point_and_label:w ##1 \q_stop + \ENdiagram_draw:xn { \l_ENdiagram_add_axis_connect_tl } + { + (\l_tmpa_tl) -- (\l_tmpa_tl -| origin-r) + } + \ENdiagram_draw:nx { } + { + (\l_tmpa_tl -| origin-r) -- ++ (3pt,0) + node[right,font=\exp_not:o \l_ENdiagram_add_axis_font_tl,\l_tmpc_tl] + { \l_tmpb_tl } + } + \group_end: + } + { + \group_begin: + \ENdiagram_get_tick_node:w ##1 \q_stop + \ENdiagram_draw:xn { \l_ENdiagram_add_axis_connect_tl } + { + (\l_tmpa_tl) -- (\l_tmpa_tl -| origin-r) + } + \ENdiagram_draw:nn { } + { + (\l_tmpa_tl -| origin-r) -- ++ (3pt,0) + } + \group_end: + } + } + } + +\cs_new_nopar:Npn \ENdiagram_add_axis_label_x_points:n #1 + { + \tl_map_inline:nn { #1 } + { + \tl_if_in:nnTF { ##1 } { [ } + { + \group_begin: + \ENdiagram_get_tick_point_and_label:w ##1 \q_stop + \ENdiagram_draw:xn { \l_ENdiagram_add_axis_connect_tl } + { + (\l_tmpa_tl) -- (\l_tmpa_tl |- origin-l) + } + \ENdiagram_draw:nx { } + { + (\l_tmpa_tl |- origin-l) -- ++ (-3pt,0) + node[below,font=\exp_not:o \l_ENdiagram_add_axis_font_tl,\l_tmpc_tl] + { \l_tmpb_tl } + } + \group_end: + } + { + \group_begin: + \ENdiagram_get_tick_node:w ##1 \q_stop + \ENdiagram_draw:xn { \l_ENdiagram_add_axis_connect_tl } + { + (\l_tmpa_tl) -- (\l_tmpa_tl |- origin-l) + } + \ENdiagram_draw:nn { } + { + (\l_tmpa_tl |- origin-l) -- ++ (-3pt,0) + } + \group_end: + } + } + } + +\cs_new_nopar:Npn \ENdiagram_get_tick_arg_and_label:w #1[#2] \q_stop + { + \fp_set:Nn \l_tmpa_fp { #1 } + \ENdiagram_get_label_and_tikz:n { #2 } + } + +\cs_new_nopar:Npn \ENdiagram_get_tick_point_and_label:w (#1)[#2] \q_stop + { + \tl_set:Nn \l_tmpa_tl { #1 } + \ENdiagram_get_label_and_tikz:n { #2 } + } + +\cs_new_nopar:Npn \ENdiagram_get_tick_node:w (#1) \q_stop + { \tl_set:Nn \l_tmpa_tl { #1 } } + +\NewDocumentCommand \ENdiagram_get_label_and_tikz:n { > { \SplitArgument { 1 } { , } } m } + { \ENdiagram_get_label_and_tikz_aux:nn #1 } + +\cs_new_nopar:Npn \ENdiagram_get_label_and_tikz_aux:nn #1#2 + { + \IfNoValueF { #1 } + { \tl_set:Nn \l_tmpb_tl { #1 } } + \IfNoValueF { #2 } { \tl_set:Nn \l_tmpc_tl { #2 } } + } + +% --------------------------------------------------------------------------- % +% make origin +\bool_new:N \l_ENdiagram_origin_made_bool + +\cs_new_nopar:Npn \ENdiagram_make_origin: + { + \bool_if:NF \l_ENdiagram_origin_made_bool + { + \bool_set_true:N \l_ENdiagram_origin_made_bool + \fp_gsub:Nn \g_ENdiagram_y_min_fp { 1 } + \fp_gadd:Nn \g_ENdiagram_y_max_fp { 1 } + \fp_gsub:Nn \g_ENdiagram_x_min_fp { 1.5 } + \fp_gsub:Nn \g_ENdiagram_x_min_fp { \l_ENdiagram_diagram_l_offset_tl } + \fp_gadd:Nn \g_ENdiagram_x_max_fp { 1.5 } + \ENdiagram_draw:nn {} + { + coordinate (origin-l) at + (-1.5-\l_ENdiagram_diagram_l_offset_tl,\fp_to_tl:N \g_ENdiagram_y_min_fp ) + } + \bool_if:NT \l_ENdiagram_debug_bool + { + \fp_set:Nn \l_tmpa_tl { -1.5 } + \fp_sub:Nn \l_tmpa_tl { \l_ENdiagram_diagram_l_offset_tl } + \ENdiagram_draw:nn { red } { (origin-l) circle (2pt) } + \ENdiagram_draw:nn { font=\tiny,inner~sep=0 } + { + node[above~right,red] at (origin-l) + { ( \fp_to_tl:N \l_tmpa_tl , \fp_to_tl:N \g_ENdiagram_y_min_fp ) } + node[fill=yellow!10,below~right] at (origin-l) + { origin-l } + } + } + \ENdiagram_draw:nn {} + { + coordinate (origin-r) at + (\fp_to_tl:N \g_ENdiagram_x_max_fp ,\fp_to_tl:N \g_ENdiagram_y_min_fp ) + } + \bool_if:NT \l_ENdiagram_debug_bool + { + \ENdiagram_draw:nn { red } { (origin-r) circle (2pt) } + \ENdiagram_draw:nn { font=\tiny,inner~sep=0 } + { + node[above~right,red] at (origin-r) + { ( \fp_to_tl:N \g_ENdiagram_x_max_fp ,\fp_to_tl:N \g_ENdiagram_y_min_fp ) } + node[fill=yellow!10,below~right] at (origin-r) + { origin-r } + } + } + } + } + +% --------------------------------------------------------------------------- % +% main environment +\bool_new:N \l_ENdiagram_y_axis_left_bool +\bool_set_true:N \l_ENdiagram_y_axis_left_bool +\bool_new:N \l_ENdiagram_y_axis_right_bool +\bool_new:N \l_ENdiagram_y_label_pos_bool +\bool_set_true:N \l_ENdiagram_y_label_pos_bool +\bool_new:N \l_ENdiagram_x_axis_bool +\bool_set_true:N \l_ENdiagram_x_axis_bool +\bool_new:N \l_ENdiagram_x_label_pos_bool +\bool_set_true:N \l_ENdiagram_x_label_pos_bool +\bool_new:N \l_ENdiagram_axes_all_bool +\bool_new:N \l_ENdiagram_axes_ticks_bool +\bool_new:N \l_ENdiagram_axes_ticks_yl_bool +\bool_new:N \l_ENdiagram_axes_ticks_yr_bool +\bool_new:N \l_ENdiagram_axes_add_ticks_bool +\bool_new:N \l_ENdiagram_energy_bool +\bool_new:N \l_ENdiagram_energy_unit_bool +\bool_new:N \l_ENdiagram_energy_round_places_bool +\bool_new:N \l_ENdiagram_calculate_bool +\bool_set_true:N \l_ENdiagram_calculate_bool + +\tl_new:N \l_ENdiagram_tikz_tl +\tl_new:N \l_ENdiagram_y_axis_tikz_tl +\tl_new:N \l_ENdiagram_x_axis_tikz_tl +\tl_new:N \l_ENdiagram_axes_ticks_step_tl +\tl_set:Nn \l_ENdiagram_axes_ticks_step_tl { 1 } +\tl_new:N \l_ENdiagram_y_label_pos_tl +\tl_set:Nn \l_ENdiagram_y_label_pos_tl { pos = .5 , } +\tl_new:N \l_ENdiagram_y_label_anchor_tl +\tl_set:Nn \l_ENdiagram_y_label_anchor_tl { sloped } +\tl_new:N \l_ENdiagram_y_label_text_tl +\tl_set:Nn \l_ENdiagram_y_label_text_tl { $E$ } +\tl_new:N \l_ENdiagram_y_label_angle_tl +\tl_set:Nn \l_ENdiagram_y_label_angle_tl { 0 } +\tl_new:N \l_ENdiagram_y_label_offset_tl +\tl_new:N \l_ENdiagram_x_label_pos_tl +\tl_set:Nn \l_ENdiagram_x_label_pos_tl { pos = .5 , } +\tl_new:N \l_ENdiagram_x_label_anchor_tl +\tl_set:Nn \l_ENdiagram_x_label_anchor_tl { below } +\tl_new:N \l_ENdiagram_x_label_text_tl +\tl_set:Nn \l_ENdiagram_x_label_text_tl { $\xi$ } +\tl_new:N \l_ENdiagram_x_label_angle_tl +\tl_set:Nn \l_ENdiagram_x_label_angle_tl { 0 } +\tl_new:N \l_ENdiagram_x_label_offset_tl +\tl_new:N \l_ENdiagram_diagram_l_offset_tl +\tl_set:Nn \l_ENdiagram_diagram_l_offset_tl { 0 } +\tl_new:N \l_ENdiagram_diagram_r_offset_tl +\tl_set:Nn \l_ENdiagram_diagram_r_offset_tl { 0 } +\tl_new:N \l_ENdiagram_diagram_scale_tl +\tl_set:Nn \l_ENdiagram_diagram_scale_tl { 1 } +\tl_new:N \l_ENdiagram_diagram_unit_factor_tl +\tl_set:Nn \l_ENdiagram_diagram_unit_factor_tl { .5 } +\tl_new:N \l_ENdiagram_energy_step_tl +\tl_set:Nn \l_ENdiagram_energy_step_tl { 1 } +\tl_new:N \l_ENdiagram_energy_unit_tl +\tl_new:N \l_ENdiagram_energy_unit_separator_tl +\tl_set:Nn \l_ENdiagram_energy_unit_separator_tl { / } +\tl_new:N \l_ENdiagram_energy_zero_tl +\tl_set:Nn \l_ENdiagram_energy_zero_tl { 0 } +\tl_new:N \l_ENdiagram_energy_round_tl +\tl_set:Nn \l_ENdiagram_energy_round_tl { 3 } + +\cs_new_nopar:Npn \ENdiagram_determine_unit:n #1 + { + \dim_set:Nn \l_tmpa_dim { 1pt * \dim_ratio:nn { #1 } { 1cm } } + \tl_set:Nn \l_ENdiagram_diagram_unit_factor_tl { \dim_use:N \l_tmpa_dim } + \tl_remove_once:Nn \l_ENdiagram_diagram_unit_factor_tl { pt } + } + +\keys_define:nn { ENdiagram } + { + debug .bool_set:N = \l_ENdiagram_debug_bool , + debug .default:n = true , + draft .bool_set:N = \l_ENdiagram_debug_bool , + draft .default:n = true , + final .choice: , + final / true .code:n = + { \bool_set_false:N \l_ENdiagram_debug_bool } , + final / false .code:n = + { \bool_set_true:N \l_ENdiagram_debug_bool } , + final .default:n = true , + axes .choice: , + axes / y .code:n = + { + \bool_set_true:N \l_ENdiagram_y_axis_left_bool + \bool_set_false:N \l_ENdiagram_y_axis_right_bool + \bool_set_false:N \l_ENdiagram_x_axis_bool + } , + axes / y-l .code:n = + { + \bool_set_true:N \l_ENdiagram_y_axis_left_bool + \bool_set_false:N \l_ENdiagram_y_axis_right_bool + \bool_set_false:N \l_ENdiagram_x_axis_bool + } , + axes / y-r .code:n = + { + \bool_set_false:N \l_ENdiagram_y_axis_left_bool + \bool_set_true:N \l_ENdiagram_y_axis_right_bool + \bool_set_false:N \l_ENdiagram_x_axis_bool + } , + axes / x .code:n = + { + \bool_set_false:N \l_ENdiagram_y_axis_left_bool + \bool_set_false:N \l_ENdiagram_y_axis_right_bool + \bool_set_true:N \l_ENdiagram_x_axis_bool + } , + axes / xy .code:n = + { + \bool_set_true:N \l_ENdiagram_y_axis_left_bool + \bool_set_false:N \l_ENdiagram_y_axis_right_bool + \bool_set_true:N \l_ENdiagram_x_axis_bool + } , + axes / all .code:n = + { \bool_set_true:N \l_ENdiagram_axes_all_bool } , + axes / false .code:n = + { + \bool_set_false:N \l_ENdiagram_y_axis_left_bool + \bool_set_false:N \l_ENdiagram_y_axis_right_bool + \bool_set_false:N \l_ENdiagram_x_axis_bool + } , + y-axis .tl_set:N = \l_ENdiagram_y_axis_tikz_tl , + x-axis .tl_set:N = \l_ENdiagram_x_axis_tikz_tl , + y-label .choice: , + y-label / above .code:n = + { + \bool_set_false:N \l_ENdiagram_y_label_pos_bool + \tl_clear:N \l_ENdiagram_y_label_anchor_tl + } , + y-label / left .code:n = + { + \bool_set_true:N \l_ENdiagram_y_label_pos_bool + \tl_set:Nn \l_ENdiagram_y_label_anchor_tl { sloped } + } , +% y-label-axis .code:n = , % TODO: left/right/both + % darauf achten, dass das mit "axes" korreliert. + y-label-pos .code:n = + { \tl_set:Nn \l_ENdiagram_y_label_pos_tl { pos = #1 , } } , + y-label-offset .code:n = + { \tl_set:Nn \l_ENdiagram_y_label_offset_tl { = #1 } } , + y-label-text .tl_set:N = \l_ENdiagram_y_label_text_tl , + y-label-angle .tl_set:N = \l_ENdiagram_y_label_angle_tl , + x-label .choice: , + x-label / right .code:n = + { + \bool_set_false:N \l_ENdiagram_x_label_pos_bool + \tl_set:Nn \l_ENdiagram_x_label_anchor_tl { right } + } , + x-label / below .code:n = + { + \bool_set_true:N \l_ENdiagram_x_label_pos_bool + \tl_set:Nn \l_ENdiagram_x_label_anchor_tl { below } + } , + x-label-pos .code:n = + { \tl_set:Nn \l_ENdiagram_x_label_pos_tl { pos = #1 , } } , + x-label-offset .code:n = + { \tl_set:Nn \l_ENdiagram_x_label_offset_tl { = #1 } } , + x-label-text .tl_set:N = \l_ENdiagram_x_label_text_tl , + x-label-angle .tl_set:N = \l_ENdiagram_x_label_angle_tl , + offset .code:n = + { + \tl_set:Nn \l_ENdiagram_diagram_l_offset_tl { #1 } + \tl_set:Nn \l_ENdiagram_diagram_r_offset_tl { #1 } + } , + l-offset .tl_set:N = \l_ENdiagram_diagram_l_offset_tl , + r-offset .tl_set:N = \l_ENdiagram_diagram_r_offset_tl , + scale .tl_set:N = \l_ENdiagram_diagram_scale_tl , + unit .code:n = \ENdiagram_determine_unit:n { #1 } , + tikz .tl_set:N = \l_ENdiagram_tikz_tl , + energy-step .code:n = + \tl_set:Nn \l_ENdiagram_energy_step_tl { #1 } + \bool_set_true:N \l_ENdiagram_energy_bool , + energy-zero .tl_set:N = \l_ENdiagram_energy_zero_tl , + energy-unit .code:n = + \tl_set:Nn \l_ENdiagram_energy_unit_tl { #1 } + \bool_set_true:N \l_ENdiagram_energy_unit_bool , + energy-unit-separator .tl_set:N = \l_ENdiagram_energy_unit_separator_tl , + energy-round-places .bool_set:N = \l_ENdiagram_energy_round_places_bool , + energy-round-places .default:n = true , + energy-round .tl_set:N = \l_ENdiagram_energy_round_tl , + calculate .bool_set:N = \l_ENdiagram_calculate_bool , + calculate .default:n = true , +% TODO darauf achten, dass das mit "axes" korreliert + ticks .choice: , + ticks / y .code:n = + \bool_set_true:N \l_ENdiagram_axes_ticks_bool , + ticks / y-l .code:n = + \bool_set_true:N \l_ENdiagram_axes_ticks_yl_bool , + ticks / y-r .code:n = + \bool_set_true:N \l_ENdiagram_axes_ticks_yr_bool , + ticks / none .code:n = + \bool_set_false:N \l_ENdiagram_axes_ticks_bool + \bool_set_false:N \l_ENdiagram_axes_ticks_yl_bool + \bool_set_false:N \l_ENdiagram_axes_ticks_yr_bool , + ticks .default:n = y , + ticks-step .tl_set:N = \l_ENdiagram_axes_ticks_step_tl + } + +\NewDocumentEnvironment { endiagram } { o } + { + \IfNoValueF { #1 } { \keys_set:nn { ENdiagram } { #1 } } + \int_gzero:N \g_ENdiagram_curve_int + \cs_set_eq:NN \ENcurve \ENdiagram_curve:w + \cs_set_eq:NN \ShowNiveaus \ENdiagram_show_niveaus:w + \cs_set_eq:NN \ShowGain \ENdiagram_show_gain:w + \cs_set_eq:NN \ShowEa \ENdiagram_show_ea:w + \cs_set_eq:NN \AddAxisLabel \ENdiagram_add_axis_label:w + \cs_set_eq:NN \MakeOrigin \ENdiagram_make_origin: + \ENdiagram_start_tikzpicture:x + { + scale=\l_ENdiagram_diagram_scale_tl*\l_ENdiagram_diagram_unit_factor_tl , + \l_ENdiagram_tikz_tl + } + } + { + \ENdiagram_make_origin: + % linke y-Achse + \bool_if:NT \l_ENdiagram_energy_unit_bool + { + \tl_put_right:Nn \l_ENdiagram_y_label_text_tl + { + \tl_use:N \l_ENdiagram_energy_unit_separator_tl + \exp_args:No \si { \l_ENdiagram_energy_unit_tl } + } + } + \bool_if:nT { \l_ENdiagram_y_axis_left_bool || \l_ENdiagram_axes_all_bool } + { + \bool_if:NF \l_ENdiagram_y_label_pos_bool { \tl_clear:N \l_ENdiagram_y_label_pos_tl } + \ENdiagram_draw:xx { -> , \l_ENdiagram_y_axis_tikz_tl } + { + (-1.5-\l_ENdiagram_diagram_l_offset_tl,\fp_to_tl:N \g_ENdiagram_y_min_fp ) + -- + (-1.5-\l_ENdiagram_diagram_l_offset_tl,\fp_to_tl:N \g_ENdiagram_y_max_fp ) + node + [ + \l_ENdiagram_y_label_pos_tl + above \l_ENdiagram_y_label_offset_tl , + rotate = \l_ENdiagram_y_label_angle_tl , + \l_ENdiagram_y_label_anchor_tl + ] + { \l_ENdiagram_y_label_text_tl } + } + % TODO: "energy-zero" beachten: ticks auch am Nullpunkt starten, egal ob dort auch ein niveau sitzt + \bool_if:nT { \l_ENdiagram_axes_ticks_bool || \l_ENdiagram_axes_ticks_yl_bool } + { + \bool_set_true:N \l_ENdiagram_axes_add_ticks_bool + \fp_set:Nn \l_tmpa_fp { \g_ENdiagram_y_min_fp + \l_ENdiagram_axes_ticks_step_tl } + \bool_while_do:Nn \l_ENdiagram_axes_add_ticks_bool + { + \fp_set_eq:NN \l_tmpb_fp \l_tmpa_fp + \tl_clear:N \l_tmpc_tl + \ENdiagram_add_axis_label_yl_ticks:n { { \l_tmpa_fp [ \fp_to_tl:N \l_tmpb_fp ] } } + \fp_add:Nn \l_tmpa_fp { \l_ENdiagram_axes_ticks_step_tl } + \fp_compare:nNnF { \l_tmpa_fp } < { \g_ENdiagram_y_max_fp } + { \bool_set_false:N \l_ENdiagram_axes_add_ticks_bool } + } + } + } + % x-Achse + \bool_if:NT \l_ENdiagram_show_gain_right_bool + { + \fp_gadd:Nn \g_ENdiagram_x_max_fp { \g_ENdiagram_gain_offset_tl } + \fp_gadd:Nn \g_ENdiagram_x_max_fp { 1 } + } + \fp_gadd:Nn \g_ENdiagram_x_max_fp { \l_ENdiagram_diagram_r_offset_tl } + \bool_if:nT { \l_ENdiagram_x_axis_bool || \l_ENdiagram_axes_all_bool } + { + \bool_if:NF \l_ENdiagram_x_label_pos_bool { \tl_clear:N \l_ENdiagram_x_label_pos_tl } + \ENdiagram_draw:xx + { + \bool_if:nT + { \l_ENdiagram_x_axis_bool && !\l_ENdiagram_y_axis_right_bool && !\l_ENdiagram_axes_all_bool } + { -> , } + \l_ENdiagram_x_axis_tikz_tl + } + { + (-1.5-\l_ENdiagram_diagram_l_offset_tl,\fp_to_tl:N \g_ENdiagram_y_min_fp ) + -- + (\fp_to_tl:N \g_ENdiagram_x_max_fp ,\fp_to_tl:N \g_ENdiagram_y_min_fp ) + node + [ + \l_ENdiagram_x_label_pos_tl + rotate = \l_ENdiagram_x_label_angle_tl , + sloped , + \l_ENdiagram_x_label_anchor_tl \l_ENdiagram_x_label_offset_tl , + ] + { \exp_not:N \l_ENdiagram_x_label_text_tl } + } + } + % rechte y-Achse + \bool_if:nT { \l_ENdiagram_y_axis_right_bool || \l_ENdiagram_axes_all_bool } + { + \ENdiagram_draw:xf { -> , \l_ENdiagram_y_axis_tikz_tl } + { + (\fp_to_tl:N \g_ENdiagram_x_max_fp,\fp_to_tl:N \g_ENdiagram_y_min_fp) + -- + (\fp_to_tl:N \g_ENdiagram_x_max_fp,\fp_to_tl:N \g_ENdiagram_y_max_fp ) + } + % TODO "energy-zero" beachten! Ticks werden nicht gezeichnet, wenn nicht extra spezifiziert + \bool_if:nT { \l_ENdiagram_axes_ticks_bool || \l_ENdiagram_axes_ticks_yr_bool } + { + \bool_set_true:N \l_ENdiagram_axes_add_ticks_bool + \fp_set_eq:NN \l_tmpa_fp \g_ENdiagram_y_min_fp + \fp_add:Nn \l_tmpa_fp { \l_ENdiagram_axes_ticks_step_tl } + \bool_while_do:Nn \l_ENdiagram_axes_add_ticks_bool + { + \fp_set_eq:NN \l_tmpb_fp \l_tmpa_fp + \fp_mul:Nn \l_tmpb_fp { \l_ENdiagram_energy_step_tl } + \tl_clear:N \l_tmpc_tl + \ENdiagram_add_axis_label_yr_ticks:n { { \l_tmpa_fp [ \fp_to_tl:N \l_tmpb_fp ] } } + \fp_add:Nn \l_tmpa_fp { \l_ENdiagram_axes_ticks_step_tl } + \fp_compare:nNnF { \l_tmpa_fp } < { \g_ENdiagram_y_max_fp } + { \bool_set_false:N \l_ENdiagram_axes_add_ticks_bool } + } + } + } + \bool_if:NT \l_ENdiagram_debug_bool + { + \fp_add:Nn \g_ENdiagram_x_max_fp { 1 } + \fp_add:Nn \g_ENdiagram_y_max_fp { 1 } + \fp_sub:Nn \g_ENdiagram_x_min_fp { 1 } + \fp_sub:Nn \g_ENdiagram_y_min_fp { 1 } + \draw[help~lines,densely~dotted,opacity=.7] + (\fp_to_tl:N \g_ENdiagram_x_min_fp,\fp_to_tl:N \g_ENdiagram_y_min_fp) + grid + (\fp_to_tl:N \g_ENdiagram_x_max_fp,\fp_to_tl:N \g_ENdiagram_y_max_fp) ; + \draw[red] (0,0) circle (3pt) node[right,font=\tiny] at (0,0) {(0,0)} ; + } + \ENdiagram_end_tikzpicture: + \fp_gzero:N \g_ENdiagram_y_min_fp + \fp_gzero:N \g_ENdiagram_y_max_fp + \fp_gzero:N \g_ENdiagram_x_max_fp + \fp_gzero:N \g_ENdiagram_x_min_fp + \tl_gset:Nn \g_ENdiagram_gain_offset_tl { 0 } + \int_gzero:N \g_ENdiagram_ea_int + } + +% --------------------------------------------------------------------------- % +% setup +\NewDocumentCommand \ENsetup { om } + { + \IfNoValueTF { #1 } + { \keys_set:nn { ENdiagram } { #2 } } + { \keys_set:nn { ENdiagram / #1 } { #2 } } + } + +% --------------------------------------------------------------------------- % +% package options: +\ProcessKeysOptions { ENdiagram } + +\tex_endinput:D +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +Version history +2012/02/31 v0.0 +2012/06/26 v0.1 +2012/08/20 v0.1a - most basic necessary changes due to new l3fp module => more + revisions on various places still needed! + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% TODO +- \ENcurve und \AddAxisLabel so anpassen, dass Eingaben der Energieskala folgen?! +- revise the whole code especially with respect to fp calculations
\ No newline at end of file |