Advertisement
Guest User

Untitled

a guest
Jul 13th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. \documentclass{article}
  2. \usepackage{datatool}
  3. \usepackage[strict]{changepage}
  4. \usepackage{filecontents}
  5. \usepackage{tcolorbox}
  6. \usepackage[absolute,overlay]{textpos}
  7. \usepackage{xcolor}
  8. \usepackage{xparse}
  9.  
  10. \begin{filecontents*}{test1.csv}
  11. Acol, Bcol,Ccol
  12. Ax,Bx,1
  13. Ay,By,3
  14. A1,B22,1
  15. A2,B44,2
  16. A3,B11,3
  17. \end{filecontents*}
  18. % If you include a line such as 'A4,B55,4' without saying how \xLength and
  19. % \yLength should be set in this case, you'll get the error message:
  20. %
  21. % Package lforti Error: Encountered value '4', but no case was written for it.
  22.  
  23. \DTLloaddb{mydata1}{test1.csv}
  24.  
  25. \newlength{\xlengthForOddPages}
  26. \newlength{\xlengthForEvenPages}
  27. \newlength{\ylengthForOddPages}
  28. \newlength{\ylengthForEvenPages}
  29.  
  30. \setlength{\xlengthForOddPages}{2cm}
  31. \setlength{\xlengthForEvenPages}{10cm}
  32. \setlength{\ylengthForOddPages}{1.5cm}
  33. \setlength{\ylengthForEvenPages}{5cm}
  34.  
  35. \newif\ifmyoddpage % always set globally, contrary to \ifoddpage
  36.  
  37. \newcommand*{\xpageDependent}{%
  38. \ifmyoddpage
  39. \expandafter
  40. \xlengthForOddPages
  41. \else
  42. \expandafter
  43. \xlengthForEvenPages
  44. \fi
  45. }
  46.  
  47. \newcommand*{\ypageDependent}{%
  48. \ifmyoddpage
  49. \expandafter
  50. \ylengthForOddPages
  51. \else
  52. \expandafter
  53. \ylengthForEvenPages
  54. \fi
  55. }
  56.  
  57. \newcommand*{\mycheckoddpage}{%
  58. \checkoddpage
  59. \global\let\ifmyoddpage=\ifoddpage
  60. }
  61.  
  62. \ExplSyntaxOn
  63.  
  64. \msg_new:nnn { lforti } { unhandled-value }
  65. { Encountered~value~'\exp_not:n~{#1}',~but~no~case~was~written~for~it. }
  66.  
  67. \tl_new:N \l__lforti_cond_length_setup_conds_tl
  68. \seq_new:N \l__lforti_cond_length_setup_tmpa_seq
  69. \seq_new:N \l__lforti_cond_length_setup_tmpb_seq
  70.  
  71. % Flexible length setup that may depend on whether it is called on an odd page
  72. % or on an even page.
  73. %
  74. % #1: a LaTeX length command (or a TeX \skipdef token) to set according to
  75. % #2 and #3
  76. % #2: the value to test against
  77. % #3: a comma list describing the different cases:
  78. %
  79. % {value_1, length-for-odd-pages, length-for-even-pages},
  80. % {value_2, length-for-odd-pages, length-for-even-pages},
  81. % ...
  82. % {value_n, length-for-odd-pages, length-for-even-pages},
  83. \cs_new_protected:Npn \lforti_cond_length_setup:Nnn #1#2#3
  84. {
  85. \checkoddpage % make sure it is used on the relevant page
  86. \seq_set_from_clist:Nn \l__lforti_cond_length_setup_tmpa_seq {#3}
  87. \tl_clear:N \l__lforti_cond_length_setup_conds_tl
  88.  
  89. \seq_map_inline:Nn \l__lforti_cond_length_setup_tmpa_seq
  90. {
  91. \seq_set_from_clist:Nn \l__lforti_cond_length_setup_tmpb_seq {##1}
  92. \tl_put_right:Nx \l__lforti_cond_length_setup_conds_tl
  93. {
  94. % Value to check against
  95. { \seq_item:Nn \l__lforti_cond_length_setup_tmpb_seq { 1 } }
  96. { % Corresponding setup code for #1
  97. \exp_not:N \skip_set:Nn \exp_not:N #1
  98. {
  99. \seq_item:Nn
  100. \l__lforti_cond_length_setup_tmpb_seq
  101. { \ifoddpage 2 \else 3 \fi }
  102. }
  103. }
  104. }
  105. }
  106.  
  107. % Handle value #2 according to the cases described by #3
  108. \str_case:nVF {#2} \l__lforti_cond_length_setup_conds_tl
  109. { \msg_error:nnn { lforti } { unhandled-value } {#2} }
  110. }
  111.  
  112. \cs_generate_variant:Nn \lforti_cond_length_setup:Nnn { Nx }
  113.  
  114. % Same as \lforti_cond_length_setup:Nnn (see above), except that the second
  115. % argument will be fully expanded (\lforti_cond_length_setup:Nnn will only see
  116. % the *result* of this expansion in its #2).
  117. \NewDocumentCommand \lforticondlengthsetup { m m m }
  118. {
  119. \lforti_cond_length_setup:Nxn #1 {#2} {#3}
  120. }
  121.  
  122. \ExplSyntaxOff
  123.  
  124. \newlength{\xLength}
  125. \newlength{\yLength}
  126.  
  127.  
  128. \begin{document}
  129. \lforticondlengthsetup{\xLength}{\C}{%
  130. {1, 2cm, 4cm}, % When \C expands to 1, use 2cm on odd pages, 4cm on even pages
  131. {2, 3cm, 5cm}, % When \C expands to 2, use 3cm on odd pages, 5cm on even pages
  132. {3, 4cm, 4cm}, % When \C expands to 3, use 4cm on all pages
  133. }%
  134. \lforticondlengthsetup{\yLength}{\C}{% analogous setup for \yLength
  135. {1, 1.5cm, 12cm},
  136. {2, 2cm, 23cm},
  137. {3, 3cm, 1.5cm},
  138. }%
  139. \DTLforeach*{mydata1}{\A=Acol,\B=Bcol,\C=Ccol}%
  140. {%
  141. \begin{textblock*}{5cm}(\xLength,\yLength)
  142. \color{blue!50!black}%
  143. \noindent
  144. abc \\
  145. \texttt{\string\xLength} = \the\xLength\\
  146. \texttt{\string\yLength} = \the\yLength
  147. \end{textblock*}
  148.  
  149. \begin{tcolorbox}[width=\xLength,height=\yLength,
  150. title={Title}]
  151. \C
  152. \end{tcolorbox}
  153.  
  154. \newpage
  155. }
  156.  
  157. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement