def write(self, out, tmpdir): Question.write_begin(self, out) if self.obj.calculate.range_count: out.write('\\pgfkeyssetvalue{/sdaps/mark/range}{%s}\n' % (self.obj.calculate.range_max - self.obj.calculate.range_min + 1)) out.write('\\pgfkeyssetvalue{/sdaps/mark/rangemin}{%s}\n' % (self.obj.calculate.range_min)) out.write('\\pgfkeyssetvalue{/sdaps/mark/rangemax}{%s}\n' % (self.obj.calculate.range_max)) out.write('\\pgfkeyssetvalue{/sdaps/mark/lower}{%s}\n' % (unicode_to_latex(self.obj.answers[0]))) out.write('\\pgfkeyssetvalue{/sdaps/mark/upper}{%s}\n' % (unicode_to_latex(self.obj.answers[1]))) out.write('\\pgfkeyssetvalue{/sdaps/mark/count}{%i}\n' % (self.obj.calculate.count)) out.write('\\pgfkeyssetvalue{/sdaps/mark/stddev}{%.1f}\n' % (self.obj.calculate.standard_deviation)) for key in range(self.obj.calculate.range_min, self.obj.calculate.range_max + 1): if key in self.obj.calculate.range_values: fraction = self.obj.calculate.range_values[key] else: fraction = 0 out.write('\\pgfkeyssetvalue{/sdaps/mark/%i/fraction}{%.3f}\n' % (key, fraction)) out.write('\\pgfkeyssetvalue{/sdaps/mark/mean}{%.1f}\n' % (self.obj.calculate.mean)) out.write('\n\\markanswer\n') if self.obj.calculate.count > 0 and self.obj.calculate.values: out.write('\\begin{embedchoicequestion}\n') for box in self.obj.boxes: if box.value in self.obj.calculate.values: out.write('''\\choiceanswer{%s}{%.3f}\n''' % (unicode_to_latex(box.text), self.obj.calculate.values[box.value])) out.write('\\end{embedchoicequestion}\n') Question.write_end(self, out)
def write(self, out, tmpdir): Question.write_begin(self, out) if self.obj.calculate.count: out.write('\\pgfkeyssetvalue{/sdaps/mark/range}{%s}\n' % (len(self.obj.boxes))) out.write('\\pgfkeyssetvalue{/sdaps/mark/lower}{%s}\n' % (unicode_to_latex(self.obj.answers[0]))) out.write('\\pgfkeyssetvalue{/sdaps/mark/upper}{%s}\n' % (unicode_to_latex(self.obj.answers[1]))) out.write('\\pgfkeyssetvalue{/sdaps/mark/count}{%i}\n' % (self.obj.calculate.count)) out.write('\\pgfkeyssetvalue{/sdaps/mark/stddev}{%.1f}\n' % (self.obj.calculate.standard_deviation)) for i, fraction in sorted(self.obj.calculate.values.iteritems()): out.write('\\pgfkeyssetvalue{/sdaps/mark/%i/fraction}{%.3f}\n' % (i, fraction)) out.write('\\pgfkeyssetvalue{/sdaps/mark/mean}{%.1f}\n' % (self.obj.calculate.mean)) out.write('\n\\markanswer\n') Question.write_end(self, out)
def write(self, out, tmpdir): self.write_begin(out) if self.obj.calculate.count: for box in self.obj.boxes: out.write('''\\choiceanswer{%s}{%.3f}\n''' % (unicode_to_latex(box.text), self.obj.calculate.values[box.value])) self.write_end(out) out.write(self.text)
def write(self, tmpdir): Question.write_begin(self, out) if self.obj.calculate.count: for i in range(len(self.obj.calculate.values)): out.write('''\\choiceanswer{%s}{%.3f}{%.3f}\n''' % (unicode_to_latex(self.obj.answers[i]), self.obj.calculate.values[i], self.obj.calculate.significant[i])) Question.write_end(self, out)
def write(self, out, tmpdir): Question.write_begin(self, out) if self.obj.calculate.count: out.write('\\pgfkeyssetvalue{/sdaps/mark/range}{%s}\n' % (len(self.obj.boxes))) out.write('\\pgfkeyssetvalue{/sdaps/mark/lower}{%s}\n' % (unicode_to_latex(self.obj.answers[0]))) out.write('\\pgfkeyssetvalue{/sdaps/mark/upper}{%s}\n' % (unicode_to_latex(self.obj.answers[1]))) out.write('\\pgfkeyssetvalue{/sdaps/mark/count}{%i}\n' % (self.obj.calculate.count)) out.write('\\pgfkeyssetvalue{/sdaps/mark/stddev}{%.1f}\n' % (self.obj.calculate.standard_deviation)) for i, fraction in sorted(self.obj.calculate.values.iteritems()): out.write( '\\pgfkeyssetvalue{/sdaps/mark/%i/fraction}{%.3f}\n' % (i, fraction)) out.write('\\pgfkeyssetvalue{/sdaps/mark/mean}{%.1f}\n' % (self.obj.calculate.mean)) out.write('\n\\markanswer\n') Question.write_end(self, out)
def run(self): # run the original code build_i18n.build_i18n.run(self) dest_dir = os.path.join('build', self.dict_dir) tex_translations = os.path.join(dest_dir, self.dict_filename) # Build the tex_translations file if not os.path.isdir(dest_dir): os.makedirs(dest_dir) cmd = [ 'intltool-merge', '-d', 'tex/po', self.dict_sourcefile, tex_translations ] self.spawn(cmd) ################### # Now build the LaTeX dictionaries def extract_key_lang(key): if not key.endswith(']'): return key, None index = key.rfind('[') return key[:index], key[index + 1:-1] parser = ConfigParser.ConfigParser() parser.read(tex_translations) langs = {} keys = set() for k, v in parser.items("translations"): key, lang = extract_key_lang(k) if not key == 'tex-language': keys.add(key) continue assert lang not in langs assert v not in langs.items() langs[lang] = v # Load mapping from unicode to LaTeX command name from sdaps.utils.latex import unicode_to_latex dictfiles = [] for lang, name in langs.iteritems(): print 'building LaTeX dictionary file for language %s (%s)' % ( name, lang if lang else 'C') dictfiles.append( os.path.join(dest_dir, 'translator-sdaps-dictionary-%s.dict' % name)) f = open(dictfiles[-1], 'w') f.write( '% This file is auto-generated from gettext translations (.po files).\n' ) f.write( '% The header of the original file follows for reference:\n') f.write('%\n') for line in open(self.dict_sourcefile).readlines(): if not line.startswith('#'): break f.write('%' + line[1:]) f.write('%\n\n') f.write( '\\ProvidesDictionary{translator-sdaps-dictionary}{%s}\n\n' % name) for key in keys: if lang is not None: k = "%s[%s]" % (key, lang) else: k = key try: value = parser.get("translations", k) except ConfigParser.NoOptionError: value = parser.get("translations", key) value = value.decode('UTF-8') value = unicode_to_latex(value) f.write('\\providetranslation{%s}{%s}\n' % (key, value)) # And install the dictionary files self.distribution.data_files.append((self.dict_dir, dictfiles))
def run(self): # run the original code build_i18n.build_i18n.run(self) dest_dir = os.path.join('build', self.dict_dir) tex_translations = os.path.join(dest_dir, self.dict_filename) # Build the tex_translations file if not os.path.isdir(dest_dir): os.makedirs(dest_dir) cmd = ['intltool-merge', '-d', 'tex/po', self.dict_sourcefile, tex_translations] self.spawn(cmd) ################### # Now build the LaTeX dictionaries def extract_key_lang(key): if not key.endswith(']'): return key, None index = key.rfind('[') return key[:index], key[index+1:-1] parser = ConfigParser.ConfigParser() parser.read(tex_translations) langs = {} keys = set() for k, v in parser.items("translations"): key, lang = extract_key_lang(k) if not key == 'tex-language': keys.add(key) continue assert lang not in langs assert v not in langs.items() langs[lang] = v # Load mapping from unicode to LaTeX command name from sdaps.utils.latex import unicode_to_latex dictfiles = [] for lang, name in langs.iteritems(): print 'building LaTeX dictionary file for language %s (%s)' % (name, lang if lang else 'C') dictfiles.append(os.path.join(dest_dir, 'translator-sdaps-dictionary-%s.dict' % name)) f = open(dictfiles[-1], 'w') f.write('% This file is auto-generated from gettext translations (.po files).\n') f.write('% The header of the original file follows for reference:\n') f.write('%\n') for line in open(self.dict_sourcefile).readlines(): if not line.startswith('#'): break f.write('%' + line[1:]) f.write('%\n\n') f.write('\\ProvidesDictionary{translator-sdaps-dictionary}{%s}\n\n' % name) for key in keys: if lang is not None: k = "%s[%s]" % (key, lang) else: k = key try: value = parser.get("translations", k) except ConfigParser.NoOptionError: value = parser.get("translations", key) value = value.decode('UTF-8') value = unicode_to_latex(value) f.write('\\providetranslation{%s}{%s}\n' % (key, value)) # And install the dictionary files self.distribution.data_files.append((self.dict_dir, dictfiles))
def write_begin(self, out): # Smarter numbering handling? out.write('\\begin{choicequestion}{%s %s}\n' % (self.obj.id_str(), unicode_to_latex(self.obj.question)))
def write(self, out, tmpdir): # Smarter numbering handling? out.write('\\section*{%s %s}\n' % (self.obj.id_str(), unicode_to_latex(self.obj.title)))
def run(self): # Build the LaTeX packages and classes, note that they cannot build # out of tree currently. maindir = os.path.abspath(os.curdir) if not os.path.exists('tex/class/build.lua'): print('error: LaTeX build script is not available') print( 'Did you forget to checkout the git submodule? See README for more information.' ) os._exit(1) os.chdir('tex/class') self.spawn(['./build.lua', 'unpack']) os.chdir(maindir) files = [ os.path.join(self.tex_resultdir, f) for f in os.listdir(self.tex_resultdir) ] self.distribution.tex_files.append((self.tex_installdir, files)) # And now the LaTeX translations dest_dir = os.path.join('build', self.dict_dir) tex_translations = os.path.join(dest_dir, self.dict_filename) if not os.path.isdir(dest_dir): os.makedirs(dest_dir) cmd = [ 'intltool-merge', '-d', 'tex/po', self.dict_sourcefile, tex_translations ] self.spawn(cmd) ################### # Now build the LaTeX dictionaries def extract_key_lang(key): if not key.endswith(']'): return key, None index = key.rfind('[') return key[:index], key[index + 1:-1] parser = configparser.ConfigParser() parser.read(tex_translations) langs = {} keys = set() for k, v in parser.items("translations"): key, lang = extract_key_lang(k) if not key == 'tex-language': keys.add(key) continue assert lang not in langs assert v not in list(langs.items()) langs[lang] = v # Load mapping from unicode to LaTeX command name from sdaps.utils.latex import unicode_to_latex dictfiles = [] for lang, name in langs.items(): print('building LaTeX dictionary file for language %s (%s)' % (name, lang if lang else 'C')) dictfiles.append( os.path.join(dest_dir, 'translator-sdaps-dictionary-%s.dict' % name)) f = open(dictfiles[-1], 'w') f.write( '% This file is auto-generated from gettext translations (.po files).\n' ) f.write( '% The header of the original file follows for reference:\n') f.write('%\n') for line in open(self.dict_sourcefile).readlines(): if not line.startswith('#'): break f.write('%' + line[1:]) f.write('%\n\n') f.write( '\\ProvidesDictionary{translator-sdaps-dictionary}{%s}\n\n' % name) for key in sorted(keys): if lang is not None: k = "%s[%s]" % (key, lang) else: k = key try: value = parser.get("translations", k) except configparser.NoOptionError: value = parser.get("translations", key) value = unicode_to_latex(value) f.write('\\providetranslation{%s}{%s}\n' % (key, value)) # And install the dictionary files self.distribution.tex_files.append((self.dict_dir, dictfiles))