Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.99 KB | None | 0 0
  1. begin{align}
  2. T(x) &= ae^{-frac{(x-b)^2}{2c^2}} \
  3. frac{1}{2} < a &leq 1 label{eq:m1va} \
  4. b &= SI{25}{degreeCelsius} label{eq:m1vb} \
  5. c &= frac{5}{sqrt{2 ln{2a}}} > 0 label{eq:m1vc}
  6. end{align}
  7. aligneqs{Model 1: Condition 1}{eq:m1va}
  8. aligneqs{Model 1: Condition 2}{eq:m1vb}
  9. aligneqs{Model 1: Condition 3}{eq:m1vc}
  10.  
  11. usepackage{tocloft}
  12. newcommand{loename}{List of equations}
  13. newlistof{equations}{equ}{loename}
  14. newcommand{aligneqs}[2]% <=== HERE
  15. {addcontentsline{equ}{equations}{protectnumberline{ref{#2}}#1}}
  16.  
  17. InsertEquation{T(x) &= ae^{-frac{(x-b)^2}{2c^2}}}{Model 1: Base formula}{eq:m1gauss}
  18. InsertEquation{frac{1}{2} < a &leq 1}{Model 1: Condition 1}{eq:m1va}
  19. InsertEquation{b &= SI{25}{degreeCelsius}}{Model 1: Condition 2}{eq:m1vb}
  20. InsertEquation{c &= frac{5}{sqrt{2 ln{2a}}} > 0}{Model 1: Condition 3}{eq:m1vc}
  21. GenerateAlign
  22.  
  23. documentclass{article}
  24. usepackage{xparse}
  25. usepackage{etoolbox}
  26. usepackage{amsmath}
  27. usepackage{tocloft}
  28.  
  29. usepackage{blindtext}
  30.  
  31. % Add a new list for equations
  32. newcommand{loename}{List of equations}
  33. newlistof{equations}{equ}{loename}
  34. newcommand{aligneqs}[2]%
  35. {addcontentsline{equ}{equations}{protectnumberline{ref{#2}}#1}}
  36. setlength{cftequationsnumwidth}{2.5em}
  37.  
  38. % https://tex.stackexchange.com/q/451/53787
  39. % https://tex.stackexchange.com/q/16883/53787
  40. makeatletter
  41. % Temporary lists: store equations, references, and deferred commands
  42. gdeflisteqs{}
  43. gdeflistrefs{}
  44. gdeflistdefers{}
  45. newcounter{DeferredCommands}
  46.  
  47. % Converts a number to Roman notation
  48. % https://tex.stackexchange.com/q/9718/53787
  49. % https://tex.stackexchange.com/q/23487/53787
  50. newcommand*{rom}[1]{expandafter@slowromancapromannumeral #1@}
  51.  
  52. % Add an element to a list
  53. defaddtolist#1#2{%
  54. g@addto@macro{#1}{#2,}
  55. }
  56.  
  57. % Add an element to a list, expanding it first
  58. % https://tex.stackexchange.com/q/67367/53787
  59. defaddexpandedtolist#1#2{%
  60. edefATL@temp{noexpandg@addto@macronoexpand#1{noexpand#2,}}
  61. ATL@temp
  62. }
  63.  
  64. % Defers the execution of a command, storing it in a list
  65. DeclareDocumentCommand{DeferCommand}{mm}{%
  66. stepcounter{DeferredCommands}
  67. expandafterdefcsname DC@rom{arabic{DeferredCommands}}endcsname{#2}
  68. addexpandedtolist{#1}{DC@rom{arabic{DeferredCommands}}}
  69. }
  70.  
  71. % Inserts an equation, its reference, and its TOC line to their
  72. % respective lists
  73. DeclareDocumentCommand{InsertEquation}{mmm}{%
  74. addtolist{listeqs}{#1}
  75. addtolist{listrefs}{#3}
  76. DeferCommand{listdefers}{aligneqs{#2}{#3}}
  77. }
  78.  
  79. % Execute all the deferred commands of the given list
  80. % https://tex.stackexchange.com/q/28787/53787
  81. DeclareDocumentCommand{DeferredExecute}{m}{%
  82. @for i:=#1 do{@nameuse{i}}
  83. setcounter{DeferredCommands}{0}
  84. let#1@empty
  85. }
  86.  
  87. % http://handyfloss.net/2007.08/latex-programming-how-to-implement-conditionals/
  88. newcounter{GArepnum}
  89. newififGA@first
  90.  
  91. % Put all the equations inside a macro (first traversal) along
  92. % with placeholders for labels, substitute the placeholders with
  93. % their respective labels (second traversal), and show everything
  94. % inside an "align". After it, execute all the deferred commands
  95. % (stored when inserting an equation) that add the corresponding
  96. % lines to the list of equations.
  97. DeclareDocumentCommand{GenerateAlign}{}{%
  98. defGA@ans{}
  99.  
  100. setcounter{GArepnum}{1}
  101. GA@firsttrue
  102.  
  103. @for i:=listeqs do{%
  104. % https://tex.stackexchange.com/q/53068/53787
  105. ifxiemptyelse
  106. ifGA@first
  107. GA@firstfalse
  108. else
  109. % https://tex.stackexchange.com/q/74707/53787
  110. edefGA@temp{noexpandg@addto@macronoexpandGA@ans{noexpand\}}
  111. GA@temp
  112. fi
  113.  
  114. edefGA@temp{noexpandg@addto@macronoexpandGA@ans{i ???}}
  115. GA@temp
  116. stepcounter{GArepnum}
  117. fi
  118. }
  119.  
  120. @for j:=listrefs do{%
  121. ifxjemptyelse
  122. % https://tex.stackexchange.com/q/104506/53787
  123. begingroupedefGA@perform{endgroup
  124. noexpandpatchcmd
  125. {noexpandGA@ans}%
  126. {noexpand ???}%
  127. {noexpandlabel{unexpandedexpandafter{j}}}%
  128. {}%
  129. {}%
  130. }%
  131. GA@perform
  132. fi
  133. }
  134.  
  135. begin{align}
  136. GA@ans
  137. end{align}
  138. DeferredExecute{listdefers}
  139.  
  140. letlisteqs@empty
  141. letlistrefs@empty
  142. }
  143. makeatother
  144.  
  145. begin{document}
  146. listofequations
  147. clearpage
  148.  
  149. section*{Important formulas}
  150.  
  151. blindtext
  152.  
  153. InsertEquation{a^2 + b^2 &= c^2}{Pythagorean theorem}{eq:first}
  154. Following is eq.~ref{eq:first}, depicting Pythagora's theorem:
  155. GenerateAlign
  156.  
  157. Blindtext
  158.  
  159. InsertEquation{e &= mc^2}{Einstein Relativity theory}{eq:second}
  160. Following is eq.~ref{eq:second}, depicting Einstein's relativity theory:
  161. GenerateAlign
  162.  
  163. blindtext
  164. end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement