def write_backreferences(seen_backrefs, gallery_conf,<EOL>target_dir, fname, snippet):
example_file = os.path.join(target_dir, fname)<EOL>backrefs = scan_used_functions(example_file, gallery_conf)<EOL>for backref in backrefs:<EOL><INDENT>include_path = os.path.join(gallery_conf['<STR_LIT>'],<EOL>'<STR_LIT>' % backref)<EOL>seen = backref in seen_backrefs<EOL>with open(include_path, '<STR_LIT:a>' if seen else '<STR_LIT:w>') as ex_file:<EOL><INDENT>if not seen:<EOL><INDENT>heading = '<STR_LIT>' % backref<EOL>ex_file.write(heading + '<STR_LIT:\n>')<EOL>ex_file.write('<STR_LIT>' * len(heading) + '<STR_LIT:\n>')<EOL><DEDENT>ex_file.write(_thumbnail_div(target_dir, fname, snippet,<EOL>is_backref=True))<EOL>seen_backrefs.add(backref)<EOL><DEDENT><DEDENT>
Writes down back reference files, which include a thumbnail list
    of examples using a certain module