module Softcover module Commands module Exercises extend self def add_to_chapters! require 'securerandom' Dir["chapters/*.tex"].each do |path| str = "" in_exercise = false n = 0 line_number = 0 lines = [] File.read(path).each_line { |line| lines.push line } lines.each do |line| str += line case line when %r{\\subsubsection{Exercises}} in_exercise = true when %r{\\end{enumerate}} in_exercise = false when %r{\\item} if in_exercise && !(lines[line_number + 1] =~ /^%=