\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{dwmpcode}[2021/12/30 v0.01 Code setting in DwMP]
\RequirePackage{listings}
\RequirePackage{xcolor}
\RequirePackage{luamplib}
\definecolor{textblue}{rgb}{.2,.2,.7}
\definecolor{textred}{rgb}{0.54,0,0}
\definecolor{textgreen}{rgb}{0,0.43,0}
\definecolor{squash}{rgb}{0.793, 0.359, 0.05}
\definecolor{carrot}{rgb}{0.934, 0.445, 0.082}
\definecolor{purple}{rgb}{0.398, 0.008, 0.234}
\def\red#1{\textcolor{textred}{#1}}
\def\blue#1{\textcolor{textblue}{#1}}
\def\green#1{\textcolor{textgreen}{#1}}
\newcommand\mpstyle{\lstset{
language=Metapost,
basicstyle=\ttfamily,
keywordstyle=\color{textblue},
keywordstyle=[5]\color{squash},
keywordstyle=[6]\color{carrot},
keywordstyle=[7]\color{purple},
commentstyle=\color{textred},
stringstyle=\color{textgreen},
frame=none,
columns=fullflexible,
keepspaces=true,
xleftmargin=\parindent,
showstringspaces=false,
% keywords[1] = Syntax primitive + plain sugar
keywords=[1]{beginfig, begingroup, bye, controls, curl, verbatimtex,%
  cycle, def, delimiters, downto, else, elseif, end, enddef, endfig,%
  endfor, endgroup, etex, exitif, exitunless, expr, fi, for, forever,%
  forsuffixes, if, input, numtok, outer, primary, primarydef, range,%
  relax, scantokens, secondary, secondarydef, step, suffix, tension,%
  tertiary, tertiarydef, text, thru, until, upto, vardef, within},%
% keywords[2] = Operators - nullary, unary, binary, thing x of y
keywords=[2]{abs, and, angle, arclength, arctime, ASCII, bbox,%
  blackpart, bluepart, bounded, byte, ceiling, center, char,%
  clipped, colormodel, colorpart, cosd, counterclockwise, cutafter,%
  cutbefore, cyanpart, dashpart, decimal, dir, direction,%
  directionpoint, directiontime, div, dotprod, false, filled, floor,%
  fontpart, fontsize, glyph, gobbled, greenpart, greypart, hex,%
  infont, intersectionpoint, intersectiontimes, inverse, known,%
  length, llcorner, lrcorner, magentapart, makepath, makepen,%
  mexp, mlog, mod, normaldeviate, not, nullpen, nullpicture, oct,%
  odd, of, or, pathpart, pencircle, penoffset, penpart, point,%
  postcontrol, precontrol, readfrom, redpart, reflectedabout,%
  reverse, rotated, rotatedabout, rotatedaround, round, scaled,%
  shifted, sind, slanted, softjoin, sqrt, str, stroked, subpath,%
  substring, textpart, textual, transformed, true,%
  turningnumber, ulcorner, uniformdeviate, unitvector, unknown,%
  urcorner, whatever, xpart, xscaled, xxpart, xypart, yellowpart,%
  ypart, yscaled, yxpart, yypart, zscaled,
  top, bot, lft, rt, ulft, urt, llft, lrt},%
% keywords[3] = Commands
keywords=[3]{addto, also, batchmode, clearit, clearpen, clearxy,%
  clear_pen_memory, clip, closefrom, contour, cutdraw, dotlabel,%
  doublepath, draw, drawarrow, drawdblarrow, drawdot, drawoptions,%
  errhelp, errmessage, errorstopmode, filenametemplate, fill,%
  filldraw, fontmapfile, fontmapline, interim, label, let,%
  loggingall, makelabel, message, newinternal, nonstopmode,%
  penstroke, pickup, randomseed, readstring, save, savepen,%
  scrollmode, setbounds, shipit, shipout, show, showdependencies,%
  showtoken, showvariable, special, to, tracingall, tracingnone,%
  undraw, undrawdot, unfill, unfilldraw, write},%
% keywords[4] = Specials, fancy macros, etc
keywords=[4]{boxit, boxjoin, bpath, buildcycle, circleit, dashed,%
  dashpattern, decr, dotlabels, drawboxed, drawboxes, drawunboxed,%
  erase, fixpos, fixsize, flex, gobble, hide, image, incr, interact,%
  interpath, labels, magstep, max, min, off, on, penlabels, penpos,%
  solve, stop, superellipse, takepower, tensepath, thelabel,%
  withcmykcolor, withcolor, withgreyscale, withoutcolor, withpen,%
  withpostscript, withprescript, withrgbcolor, withalpha, z},%
% keywords[5] = Predefined variables
keywords=[5]{ahangle, ahlength, arrowhead, background, bboxmargin,%
  charcode, circmargin, currentpen, currentpicture, cuttings, day,%
  defaultcolormodel, defaultdx, defaultdy, defaultfont, defaultpen,%
  defaultscale, dotlabeldiam, eps, extra_beginfig, extra_endfig,%
  hour, hppp, jobname, join_radius, labeloffset, laboff, labxf,%
  labyf, linecap, linejoin, minute, miterlimit, month, mpprocset,%
  numberprecision, numbersystem, outputfilename, outputformat,%
  outputformatoptions, outputtemplate, pausing, pen_bot, pen_lft,%
  pen_rt, pen_top, prologues, restoreclipcolor, showstopping, time,%
  tolerance, tracingcapsules, tracingchoices, tracingcommands,%
  tracingequations, tracinglostchars, tracingmacros, tracingonline,%
  tracingoutput, tracingrestores, tracingspecs, tracingstats,%
  tracingtitles, troffmode, truecorners, vppp, warningcheck, year},%
% keywords[6] = Constants
keywords=[6]{base_name, base_version, beveled, black,%
  blankpicture, blue, bp, butt, cc, cm, dd, ditto, down, EOF,%
  epsilon, evenly, fullcircle, green, halfcircle, identity, in, left,%
  mitered, mm, mpversion, origin, pc, penrazor, penspeck,%
  pensquare, pt, quartercircle, red, right, rounded, squared,%
  unitsquare, up, white, withdots, infinity},%
% keywords[7] = Types
keywords=[7]{boolean, cmykcolor, color, numeric, pair, path, pen,%
  picture, rgbcolor, string, transform},%
sensitive=true,%
alsoother={0123456789$@},%
morestring=[s]{verbatimtex}{etex},%
morestring=[s]{btex}{etex}%
}}
\lstnewenvironment{smallcode}[1][]{\mpstyle\lstset{basicstyle=\small\ttfamily,#1}}{}
\lstnewenvironment{code}[1][]{\mpstyle\lstset{#1}}{}
\newcommand\mpexternal[2][]{{\mpstyle\lstinputlisting[#1]{#2}}}
\newcommand\smallmpexternal[2][]{{\mpstyle\lstinputlisting[basicstyle=\small\ttfamily,#1]{#2}}}
\newcommand\mpl[1]{{\normalfont\mpstyle\lstinline!#1!}}
%
\newcommand\texstyle{\lstset{
language=[LaTeX]Tex,
basicstyle=\ttfamily,
keywordstyle=\color{textblue},
commentstyle=\color{textred},
stringstyle=\color{textgreen},
frame=none,
columns=fullflexible,
keepspaces=true,
xleftmargin=\parindent,
showstringspaces=false,
morekeywords={everymplib, everyendmplib, setmainfont,
mplibtextextlabel, mplibnumbersystem, mplibsetformat, mplibshowlog},
}}
\lstnewenvironment{texcode}[1][]{\texstyle\lstset{basicstyle=\small\ttfamily,#1}}{}
\newcommand\txl[1]{{\texstyle\lstinline!#1!}}
\newcommand\texternal[2][]{{\texstyle\lstinputlisting[#1]{#2}}}
\newcommand\smalltexternal[2][]{{\texstyle\lstinputlisting[basicstyle=\small\ttfamily,#1]{#2}}}
%
% Labels..
%
\newcommand\sep[1]{$\vcenter{\begin{mplibcode}
picture T; T = thelabel(TEX("\ttfamily " & #1), origin); interim bboxmargin := 3; path p; p = bbox T;
path S; S = superellipse(point 3/2 of p, point 5/2 of p, point 7/2 of p, point 1/2 of p, 0.78);
string x; x = substring (0, 1) of #1;
fill S withcolor if x = "m": 7/8[red, white] elseif x = "c": 7/8[blue, white] else: white fi;
draw S; draw T;\end{mplibcode}}$}
%
\endinput
