Skip to content

Commit

Permalink
process brackets in html
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason2Brownlee committed Jan 24, 2011
1 parent 534d45d commit 1b43650
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion book/a_physical/simulated_annealing.tex
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ \subsection{Procedure}
\If{\Cost{\Candidate} $\leq$ \Cost{\Best}} {
\Best $\leftarrow$ \Candidate\;
}
}\ElseIf{\Exp{$\frac{\Cost{\Current}-\Cost{\Candidate}}{\Temp}$} $>$ \Rand{}} {
}\ElseIf{\Exp{ $\frac{\Cost{\Current} - \Cost{\Candidate}}{\Temp}$ } $>$ \Rand{}} {
\Current $\leftarrow$ \Candidate\;
}
}
Expand Down
17 changes: 11 additions & 6 deletions web/generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ def replace_functions(map, line)
# same with func map, end in {
map.keys.each do |key|
line = line.gsub("\\#{key}{", "#{pseudocode_term map[key]}{") # bracket
line = line.gsub("\\#{key}(", "#{pseudocode_term map[key]}(") # bracket
end
# easy no param functions
line = line.gsub("{}", "()")
Expand Down Expand Up @@ -834,10 +835,14 @@ def process_pseudocode(lines, caption=nil)
# take out the math
math = []
line.scan(/\$([^$]+)\$/) {|m| math << m.to_s } # $$
# brackets
line = line.gsub("{", "(")
line = line.gsub("}", ")")
# put the math back
if !math.empty?
# process the math
math.each_index do |i|
puts math[i]
# puts math[i]
math[i] = replace_data(datamap, math[i])
math[i] = replace_functions(funcmap, math[i])
# remove all sub-math
Expand Down Expand Up @@ -867,13 +872,13 @@ def process_pseudocode(lines, caption=nil)
line = line.gsub("\\Break", "#{pseudocode_keyword("Break")}")
line = line.gsub("TRUE", "#{pseudocode_keyword("True")}")
line = line.gsub("FALSE", "#{pseudocode_keyword("False")}")
if line.strip == "}{"
if line.strip == "}{" or line.strip == ")("
line = line.gsub("}{", "#{pseudocode_keyword("Else")}")
elsif line.strip == "}"
line = line.gsub(")(", "#{pseudocode_keyword("Else")}") # HACK
elsif line.strip == "}" or line.strip == ")" # hack
line = line.gsub("}", "#{pseudocode_keyword("End")}")
end


line = line.gsub(")", "#{pseudocode_keyword("End")}") # HACK
end
# replace tabs
line = line.gsub("\t", "&nbsp;&nbsp;&nbsp;&nbsp;")
# now replace new lines
Expand Down

0 comments on commit 1b43650

Please sign in to comment.