Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file metapost.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231(**************************************************************************)(* *)(* Copyright (C) Johannes Kanig, Stephane Lescuyer *)(* Jean-Christophe Filliatre, Romain Bardou and Francois Bobot *)(* *)(* This software is free software; you can redistribute it and/or *)(* modify it under the terms of the GNU Library General Public *)(* License version 2.1, with the special exception on linking *)(* described in file LICENSE. *)(* *)(* This software is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *)(* *)(**************************************************************************)openFormatletprintfmtic=(* resetting is actually not needed; variables other than
x,y are not local to figures *)(* Compile.reset (); *)let()=Duplicate.commandpiccinletc=Compile.commandpic_cmdcinfprintffmt"@[beginfig(%d)@\n @[%a@] endfig;@]@."iMPprint.commandcletprint_preludesfmt()=fprintffmt"input metafun.mp ; %% some initializations and auxiliary macros\n\
%% macros that support special features\n\
@\n";fprintffmt"prologues := 0;@\n";fprintffmt"mpprocset := 0;@\n";fprintffmt"verbatimtex@\n";fprintffmt"%%&latex@\n";fprintffmt"%s"s;fprintffmt"\\begin{document}@\n";fprintffmt"etex@\n"(* fprintf fmt "input boxes;@\n" *)(** take a list of figures [l] and write the code to the formatter in argument
*)letmpbn?preludel=letprelude=matchpreludewithNone->Defaults.get_prelude()|Somes->sinletf=File.set_ext(File.from_stringbn)"mp"inFile.write_to_formattedf(funfmt->print_preludepreludefmt();leti=ref1inletm=List.fold_left(funacc(t,f)->letacc=Misc.IntMap.add!itaccinprintfmt!if;incri;acc)Misc.IntMap.emptylinfprintffmt"end@.";(f,m))(* batch processing *)letdump_tex?preludef=letc=open_out(f^".tex")inletfmt=formatter_of_out_channelcin(matchpreludewith|None->fprintffmt"\\documentclass[a4paper]{article}"|Somes->fprintffmt"%s@\n"s);fprintffmt"\\usepackage{graphicx}";fprintffmt"%%%%%%%%\n\
%% For specials in mps\n\
\\LoadMetaPostSpecialExtensions\n\
%%%%%%%%\n";fprintffmt"\\begin{document}@\n";fprintffmt"\\begin{center}@\n";Queue.iter(fun(s,_)->fprintffmt"\\hrulefill\\verb!%s!\\hrulefill\\\\[1em]@\n"s;fprintffmt"\\includegraphics{%s}\\\\@\n"(File.to_string(File.set_ext(File.from_strings)"mps"));fprintffmt"\\hrulefill\\\\@\n@\n\\medskip@\n")Defaults.figures;fprintffmt"\\end{center}@\n";fprintffmt"\\end{document}@.";close_outcletcall_latex?inv?outv?verbosef=letcmd=Misc.sprintf"latex -interaction=nonstopmode %s"finMisc.call_cmd?inv?outv?verbosecmdletcall_mpost?inv?outv?verbosef=letcmd=Misc.sprintf"mpost -interaction=nonstopmode %s"(File.to_stringf)inMisc.call_cmd?inv?outv?verbosecmdletprint_latex_error()=ifSys.file_exists"mpxerr.tex"then(Printf.printf"############################################################\n";Printf.printf"LaTeX has found an error in your file. Here is its output:\n";ignore(call_latex~outv:true"mpxerr.tex"))(* else
Printf.printf
"There were (ignored) errors during the execution of metapost. \
Execute with option -v to see the errors.\n" *)letmps?prelude?(verbose=false)bnfigl=iffigl<>[]then(lettargets=List.map(fun(bn,_)->File.set_ext(File.from_stringbn)"mps")figlinletf,m=mpbn?preludefiglinlets=call_mpost~verbosefinifs<>0thenprint_latex_error();Misc.IntMap.iter(funkto_->letfrom=File.set_extf(string_of_intk)inletto_=File.mkto_"mps"inFile.movefromto_)m;targets)else[]letcall_mptopdf?inv?outv?verbosef=(* assume that f is ps file or sth like that *)ignore(Misc.call_cmd?inv?outv?verbose(sprintf"mptopdf %s"(File.to_stringf)));letout=File.set_extf"pdf"inFile.move(File.appendout("-"^File.extensionf))out;outletcall_convert?inv?outv?verbosefromto_=ignore(Misc.call_cmd?inv?outv?verbose(sprintf"convert -density 600x600 \"%s\" \"%s\""(File.to_stringfrom)(File.to_stringto_)));to_letpdf?prelude?verbosebnfigl=letl=mps?prelude?verbosebnfiglinList.map(funf->call_mptopdf?verbosef)lletpng?prelude?verbosebnfigl=letpdfl=pdf?prelude?verbosebnfiglinList.map(funf->call_convert?verbosef(File.set_extf"png"))pdflletwrap_tempdirfsuffix?prelude?verbose?cleanbnfigl=letdo_from_to_=(* first copy necessary files, then do your work *)List.iter(funf->File.copy(File.placefrom_f)(File.placeto_f))(Defaults.get_required_files());letl=f?prelude?verbosebnfiglin(l,l)inMetapost_tool.tempdir?clean"mlpost"("metapost-"^suffix)do_lettemp_mp?prelude?verbose:_?clean:_=mp?preludelettemp_mps=wrap_tempdirmps"mps"lettemp_pdf=wrap_tempdirpdf"pdf"lettemp_png=wrap_tempdirpng"png"letwrap_dumpf?prelude?verbose?cleanbn=letbn=Filename.basenamebninignore(f?prelude?verbose?cleanbn(Defaults.emited()))letdump_mp=wrap_dumptemp_mpletdump_mps=wrap_dumptemp_mpsletdump_pdf=wrap_dumptemp_pdfletdump_png=wrap_dumptemp_pngletgenerate?prelude?verbose?cleanbnfigl=ignore(temp_mps?prelude?verbose?cleanbnfigl)letslideshowlk=letl=List.mapPicture.makelinletl'=Command.seq(List.map(funp->Command.draw~color:Color.white(Picture.bboxp))l)inletx=ref(k-1)inList.map(funp->incrx;(!x,Command.seq[l';Command.draw_picp]))lletemit_slideshowsl=letl=slideshowl0inList.iter(fun(i,fig)->Defaults.emit(s^string_of_inti)fig)lletdumpable()=Queue.iter(fun(s,_)->Printf.printf"%s\n"s)Defaults.figuresletfigures_names()=List.rev(Queue.fold(funacc(s,_)->s::acc)[]Defaults.figures)letdependmyname=Queue.iter(fun(s,_)->Printf.printf"%s"(File.to_string(File.mks"fmlpost")))Defaults.figures;Printf.printf" : %s.cmlpost\n"myname(* compatibility *)letread_prelude_from_tex_file=Metapost_tool.read_prelude_from_tex_fileletemit=Defaults.emitletdump?prelude?(pdf=false)?eps:_?verbose?cleans=ifpdfthendump_pdf?prelude?verbose?cleanselsedump_mps?prelude?verbose?cleansletset_filename_prefix=Defaults.set_filename_prefixtypejob=Defaults.jobtypejobs=Defaults.jobs