Greetings from #rdcHQ! This week in the MathML Track, we made a big step towards finalizing how our equations will be integrated into the Title 24 documents. Jasper wrote a Ruby script that will solve that piece of the puzzle by creating a wrapper around each equation as outlined earlier in the program. This code will ultimately be published in github during our documentation phase.

Our draft code is below … More news as it develops! (We also have more equations to add to the repository … stay tuned!)

grem.rb (draft)

Note: We are still working out details on how to gracefully degrade to the generated SVG, and in the absence of an SVG, the original JPG image.

name = ARGV.shift #get individual filenames from helper.rb
# grem.rb: grep for MathML
# Jasper Shumaker-Pruitt
# extracts MathML from html files
# see helper.rb for instructions

File.open(name, "w") do |writefile|   #open a new file of the same name
  writefile.puts '<span class="display">
	<span id="equation-item[n]" class="formula">
		<span class="label">
			[EQUATION IDENTIFIER]
		</span>
		<span class="math">' #write some html to that file

  current_state = 0
  while line = gets    #iterate through the lines from original file
    if line.index("<math") #look for an opening math tag
      current_state = 1
    end
    if current_state > 0    #write the content from opening to closing math tags
      writefile.puts line
    end
    if line.index("</math") #quit writing when closing tag is found
      current_state -= 1
    end
  end
  writefile.puts '
		</span>
	</span>
</span>'  #write the rest of the html wrapper
end

helper.rb (draft)

Note: This code could be repurposed to convert an entire directory of xml/mml/html documents to svg with SVGMath.

#helper.rb
#Jasper Shumaker-Pruitt
#usage:
#1) create new destination directory
#2)into the command line type: ruby helper.rb SourceDir DestinationDir
# i.e. ruby helper.rb /home/foo/sourcedir /home/foo/destinationdir for a #computer named foo

origin = ARGV.shift #retrieve and store user input for source and destination
destin = ARGV.shift #directories
fileNameArray=`ls #{origin}`.split #create an array of filenames in source dir
fileNameArray.each do |htmlFile|  #iterate through array
 if !(htmlFile.index("~"))#ignore html backup files
 	system("ruby grem.rb #{destin}/#{htmlFile} < #{origin}/#{htmlFile}")
        #execute grem for each file
 end
end