#! /usr/bin/env python ############################################## # Generate a fakeasapsym.sty file that works # # with pdfLaTeX. # # # # Author: Scott Pakin .enc to fakeasapsym.enc. with open('fakeasapsym.map') as r: for ln in r: fields = ln.split() if len(fields) == 6 and fields[0] == 'fakeasapsym': mapfields = fields enc = mapfields[4][2:] os.rename(enc, 'fakeasapsym.enc') # Remove fakeasapsym.map as it is no longer needed. os.remove('fakeasapsym.map') # Return a map-file line that can be used in a .sty file. mapfields[4] = mapfields[4][:2] + 'fakeasapsym.enc' return ' '.join(mapfields) def write_style_file(sty, map_line, sym_glyphs): 'Derive fakeasapsym.sty from asapsym.sty.' # Acquire the ProvidesPackage description from asapsym.sty. with open(sty) as r: all_sty = r.read() provides_re = re.compile(r'\\ProvidesPackage\{asapsym\}\s*\[(.*?)\]', re.DOTALL) desc = provides_re.search(all_sty)[1] # Create fakeasapsym.sty. with open('fakeasapsym.sty', 'w') as w: # Package header w.write('''\ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % This is a generated file. DO NOT EDIT. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \\NeedsTeXFormat{LaTeX2e} ''') w.write('\\ProvidesPackage{fakeasapsym}[%s]\n\n' % desc) # Font definition w.write('\\pdfmapline{=%s}\n' % map_line) w.write('\\font\\fakeasapsym=fakeasapsym at 10pt\n\n') # Primitive symbol list signs = [] for i, (sym, glyph) in enumerate(sym_glyphs): w.write('\\DeclareRobustCommand*{\\asap%s}' '{{\\fakeasapsym\\char"%02X}} %% %s\n' % (sym, i, glyph)) if sym[-4:] == 'Sign' and sym != 'NotSign': signs.append(sym) w.write('\n') # Composed symbol list. for sym in signs: w.write('\\DeclareRobustCommand*{\\asapNot%s}' '{\\asap%s\\llap{\\asapNotSign}}\n' % (sym, sym,)) w.write('\n') # Package trailed w.write('\\endinput\n') # Generate a pdfLaTeX-compatible version of asamsym.sty. tex = kpsewhich('asapsym-generic.tex') sym_glyphs = parse_definitions(tex) write_encoding(sym_glyphs) ttf = kpsewhich('Asap-Symbol.otf') map_line = generate_font_files(ttf) os.remove('fakeasapsym-in.enc') sty = kpsewhich('asapsym.sty') write_style_file(sty, map_line, sym_glyphs)