   else
     'xlink:href'
 
+maybeWrite = (filename, data) ->
+  ## Writes data to filename, unless the file is already identical to data.
+  ## Returns whether the write actually happened.
+  try
+    if data == fs.readFileSync filename, encoding: 'utf8'
+      return false
+  fs.writeFileSync filename, data
+  true
+
 class Drawing extends Input
   hrefAttr: -> hrefAttr @settings
   load: (data) ->

    path.format filename2
  writeSVG: (mappings, styles, filename) ->
    for drawing in @drawings
      drawing.writeSVG mappings, styles, @subfilename '.svg', drawing
  writeTeX: (filename) ->
    for drawing in @drawings
      subfilename = @subfilename '.svg_tex', drawing

         outputDir?
        relativeDir = path.relative (outputDir ? '.'), (graphicDir ? '.')
      filename = path.format filename
    if maybeWrite filename, @renderTeX filename, relativeDir
      console.log ' &', filename
      filename
    else
      console.log ' &', filename, '(unchanged)'
      null

class ASCIIDrawing extends Drawing
  @title: "ASCII drawing (one character per symbol)"
