"use strict";
const Color = require("color");
const unifiedLatexUtilPegjs = require("@unified-latex/unified-latex-util-pegjs");
const macros = {
  substitutecolormodel: {
    signature: "m m",
    renderInfo: { breakAround: true }
  },
  selectcolormodel: {
    signature: "m",
    renderInfo: { breakAround: true }
  },
  definecolor: {
    signature: "o m m m",
    renderInfo: { breakAround: true }
  },
  providecolor: {
    signature: "o m m m",
    renderInfo: { breakAround: true }
  },
  colorlet: {
    signature: "o m o m",
    renderInfo: { breakAround: true }
  },
  definecolorset: {
    signature: "o m m m",
    renderInfo: { breakAround: true }
  },
  providecolorset: {
    signature: "o m m m m",
    renderInfo: { breakAround: true }
  },
  preparecolor: {
    signature: "o m m m",
    renderInfo: { breakAround: true }
  },
  preparecolorset: {
    signature: "o m m m m",
    renderInfo: { breakAround: true }
  },
  DefineNamedColor: {
    signature: "m m m m",
    renderInfo: { breakAround: true }
  },
  definecolors: {
    signature: "m",
    renderInfo: { breakAround: true }
  },
  providecolors: {
    signature: "m",
    renderInfo: { breakAround: true }
  },
  color: { signature: "o m", renderInfo: { breakAround: true } },
  textcolor: { signature: "o m m", renderInfo: { inParMode: true } },
  pagecolor: { signature: "o m" },
  colorbox: { signature: "o m m" },
  fcolorbox: { signature: "o m o m m" },
  boxframe: { signature: "o m" },
  testcolor: { signature: "o m" },
  blendcolors: { signature: "s m" },
  maskcolors: { signature: "o m" },
  definecolorseries: {
    signature: "m m m o m o m",
    renderInfo: { breakAround: true }
  },
  resetcolorseries: {
    signature: "o m",
    renderInfo: { breakAround: true }
  },
  rowcolors: { signature: "s o m m m" },
  extractcolorspec: { signature: "m m" },
  extractcolorspecs: { signature: "m m m" },
  convertcolorspec: { signature: "m m m m" }
};
const environments = {
  testcolors: { signature: "o", renderInfo: { pgfkeysArgs: true } }
};
const fromRgb = ([r, g, b]) => Color([r * 255, g * 255, b * 255], "rgb");
const DVI_PS_NAMES = {
  Apricot: Color("#FBB982"),
  Aquamarine: Color("#00B5BE"),
  Bittersweet: Color("#C04F17"),
  Black: Color("#221E1F"),
  Blue: Color("#2D2F92"),
  BlueGreen: Color("#00B3B8"),
  BlueViolet: Color("#473992"),
  BrickRed: Color("#B6321C"),
  Brown: Color("#792500"),
  BurntOrange: Color("#F7921D"),
  CadetBlue: Color("#74729A"),
  CarnationPink: Color("#F282B4"),
  Cerulean: Color("#00A2E3"),
  CornflowerBlue: Color("#41B0E4"),
  Cyan: Color("#00AEEF"),
  Dandelion: Color("#FDBC42"),
  DarkOrchid: Color("#A4538A"),
  Emerald: Color("#00A99D"),
  ForestGreen: Color("#009B55"),
  Fuchsia: Color("#8C368C"),
  Goldenrod: Color("#FFDF42"),
  Gray: Color("#949698"),
  Green: Color("#00A64F"),
  GreenYellow: Color("#DFE674"),
  JungleGreen: Color("#00A99A"),
  Lavender: Color("#F49EC4"),
  LimeGreen: Color("#8DC73E"),
  Magenta: Color("#EC008C"),
  Mahogany: Color("#A9341F"),
  Maroon: Color("#AF3235"),
  Melon: Color("#F89E7B"),
  MidnightBlue: Color("#006795"),
  Mulberry: Color("#A93C93"),
  NavyBlue: Color("#006EB8"),
  OliveGreen: Color("#3C8031"),
  Orange: Color("#F58137"),
  OrangeRed: Color("#ED135A"),
  Orchid: Color("#AF72B0"),
  Peach: Color("#F7965A"),
  Periwinkle: Color("#7977B8"),
  PineGreen: Color("#008B72"),
  Plum: Color("#92268F"),
  ProcessBlue: Color("#00B0F0"),
  Purple: Color("#99479B"),
  RawSienna: Color("#974006"),
  Red: Color("#ED1B23"),
  RedOrange: Color("#F26035"),
  RedViolet: Color("#A1246B"),
  Rhodamine: Color("#EF559F"),
  RoyalBlue: Color("#0071BC"),
  RoyalPurple: Color("#613F99"),
  RubineRed: Color("#ED017D"),
  Salmon: Color("#F69289"),
  SeaGreen: Color("#3FBC9D"),
  Sepia: Color("#671800"),
  SkyBlue: Color("#46C5DD"),
  SpringGreen: Color("#C6DC67"),
  Tan: Color("#DA9D76"),
  TealBlue: Color("#00AEB3"),
  Thistle: Color("#D883B7"),
  Turquoise: Color("#00B4CE"),
  Violet: Color("#58429B"),
  VioletRed: Color("#EF58A0"),
  White: Color("#FFFFFF"),
  WildStrawberry: Color("#EE2967"),
  Yellow: Color("#FFF200"),
  YellowGreen: Color("#98CC70"),
  YellowOrange: Color("#FAA21A")
};
const SVG_NAMES = {
  AliceBlue: fromRgb([0.94, 0.972, 1]),
  AntiqueWhite: fromRgb([0.98, 0.92, 0.844]),
  Aqua: fromRgb([0, 1, 1]),
  Aquamarine: fromRgb([0.498, 1, 0.83]),
  Azure: fromRgb([0.94, 1, 1]),
  Beige: fromRgb([0.96, 0.96, 0.864]),
  Bisque: fromRgb([1, 0.894, 0.77]),
  Black: fromRgb([0, 0, 0]),
  BlanchedAlmond: fromRgb([1, 0.92, 0.804]),
  Blue: fromRgb([0, 0, 1]),
  BlueViolet: fromRgb([0.54, 0.17, 0.888]),
  Brown: fromRgb([0.648, 0.165, 0.165]),
  BurlyWood: fromRgb([0.87, 0.72, 0.53]),
  CadetBlue: fromRgb([0.372, 0.62, 0.628]),
  Chartreuse: fromRgb([0.498, 1, 0]),
  Chocolate: fromRgb([0.824, 0.41, 0.116]),
  Coral: fromRgb([1, 0.498, 0.312]),
  CornflowerBlue: fromRgb([0.392, 0.585, 0.93]),
  Cornsilk: fromRgb([1, 0.972, 0.864]),
  Crimson: fromRgb([0.864, 0.08, 0.235]),
  Cyan: fromRgb([0, 1, 1]),
  DarkBlue: fromRgb([0, 0, 0.545]),
  DarkCyan: fromRgb([0, 0.545, 0.545]),
  DarkGoldenrod: fromRgb([0.72, 0.525, 0.044]),
  DarkGray: fromRgb([0.664, 0.664, 0.664]),
  DarkGreen: fromRgb([0, 0.392, 0]),
  DarkGrey: fromRgb([0.664, 0.664, 0.664]),
  DarkKhaki: fromRgb([0.74, 0.716, 0.42]),
  DarkMagenta: fromRgb([0.545, 0, 0.545]),
  DarkOliveGreen: fromRgb([0.332, 0.42, 0.185]),
  DarkOrange: fromRgb([1, 0.55, 0]),
  DarkOrchid: fromRgb([0.6, 0.196, 0.8]),
  DarkRed: fromRgb([0.545, 0, 0]),
  DarkSalmon: fromRgb([0.912, 0.59, 0.48]),
  DarkSeaGreen: fromRgb([0.56, 0.736, 0.56]),
  DarkSlateBlue: fromRgb([0.284, 0.24, 0.545]),
  DarkSlateGray: fromRgb([0.185, 0.31, 0.31]),
  DarkSlateGrey: fromRgb([0.185, 0.31, 0.31]),
  DarkTurquoise: fromRgb([0, 0.808, 0.82]),
  DarkViolet: fromRgb([0.58, 0, 0.828]),
  DeepPink: fromRgb([1, 0.08, 0.576]),
  DeepSkyBlue: fromRgb([0, 0.75, 1]),
  DimGray: fromRgb([0.41, 0.41, 0.41]),
  DimGrey: fromRgb([0.41, 0.41, 0.41]),
  DodgerBlue: fromRgb([0.116, 0.565, 1]),
  FireBrick: fromRgb([0.698, 0.132, 0.132]),
  FloralWhite: fromRgb([1, 0.98, 0.94]),
  ForestGreen: fromRgb([0.132, 0.545, 0.132]),
  Fuchsia: fromRgb([1, 0, 1]),
  Gainsboro: fromRgb([0.864, 0.864, 0.864]),
  GhostWhite: fromRgb([0.972, 0.972, 1]),
  Gold: fromRgb([1, 0.844, 0]),
  Goldenrod: fromRgb([0.855, 0.648, 0.125]),
  Gray: fromRgb([0.5, 0.5, 0.5]),
  Green: fromRgb([0, 0.5, 0]),
  GreenYellow: fromRgb([0.68, 1, 0.185]),
  Grey: fromRgb([0.5, 0.5, 0.5]),
  Honeydew: fromRgb([0.94, 1, 0.94]),
  HotPink: fromRgb([1, 0.41, 0.705]),
  IndianRed: fromRgb([0.804, 0.36, 0.36]),
  Indigo: fromRgb([0.294, 0, 0.51]),
  Ivory: fromRgb([1, 1, 0.94]),
  Khaki: fromRgb([0.94, 0.9, 0.55]),
  Lavender: fromRgb([0.9, 0.9, 0.98]),
  LavenderBlush: fromRgb([1, 0.94, 0.96]),
  LawnGreen: fromRgb([0.488, 0.99, 0]),
  LemonChiffon: fromRgb([1, 0.98, 0.804]),
  LightBlue: fromRgb([0.68, 0.848, 0.9]),
  LightCoral: fromRgb([0.94, 0.5, 0.5]),
  LightCyan: fromRgb([0.88, 1, 1]),
  LightGoldenrod: fromRgb([0.933, 0.867, 0.51]),
  LightGoldenrodYellow: fromRgb([0.98, 0.98, 0.824]),
  LightGray: fromRgb([0.828, 0.828, 0.828]),
  LightGreen: fromRgb([0.565, 0.932, 0.565]),
  LightGrey: fromRgb([0.828, 0.828, 0.828]),
  LightPink: fromRgb([1, 0.712, 0.756]),
  LightSalmon: fromRgb([1, 0.628, 0.48]),
  LightSeaGreen: fromRgb([0.125, 0.698, 0.668]),
  LightSkyBlue: fromRgb([0.53, 0.808, 0.98]),
  LightSlateBlue: fromRgb([0.518, 0.44, 1]),
  LightSlateGray: fromRgb([0.468, 0.532, 0.6]),
  LightSlateGrey: fromRgb([0.468, 0.532, 0.6]),
  LightSteelBlue: fromRgb([0.69, 0.77, 0.87]),
  LightYellow: fromRgb([1, 1, 0.88]),
  Lime: fromRgb([0, 1, 0]),
  LimeGreen: fromRgb([0.196, 0.804, 0.196]),
  Linen: fromRgb([0.98, 0.94, 0.9]),
  Magenta: fromRgb([1, 0, 1]),
  Maroon: fromRgb([0.5, 0, 0]),
  MediumAquamarine: fromRgb([0.4, 0.804, 0.668]),
  MediumBlue: fromRgb([0, 0, 0.804]),
  MediumOrchid: fromRgb([0.73, 0.332, 0.828]),
  MediumPurple: fromRgb([0.576, 0.44, 0.86]),
  MediumSeaGreen: fromRgb([0.235, 0.7, 0.444]),
  MediumSlateBlue: fromRgb([0.484, 0.408, 0.932]),
  MediumSpringGreen: fromRgb([0, 0.98, 0.604]),
  MediumTurquoise: fromRgb([0.284, 0.82, 0.8]),
  MediumVioletRed: fromRgb([0.78, 0.084, 0.52]),
  MidnightBlue: fromRgb([0.098, 0.098, 0.44]),
  MintCream: fromRgb([0.96, 1, 0.98]),
  MistyRose: fromRgb([1, 0.894, 0.884]),
  Moccasin: fromRgb([1, 0.894, 0.71]),
  NavajoWhite: fromRgb([1, 0.87, 0.68]),
  Navy: fromRgb([0, 0, 0.5]),
  NavyBlue: fromRgb([0, 0, 0.5]),
  OldLace: fromRgb([0.992, 0.96, 0.9]),
  Olive: fromRgb([0.5, 0.5, 0]),
  OliveDrab: fromRgb([0.42, 0.556, 0.136]),
  Orange: fromRgb([1, 0.648, 0]),
  OrangeRed: fromRgb([1, 0.27, 0]),
  Orchid: fromRgb([0.855, 0.44, 0.84]),
  PaleGoldenrod: fromRgb([0.932, 0.91, 0.668]),
  PaleGreen: fromRgb([0.596, 0.985, 0.596]),
  PaleTurquoise: fromRgb([0.688, 0.932, 0.932]),
  PaleVioletRed: fromRgb([0.86, 0.44, 0.576]),
  PapayaWhip: fromRgb([1, 0.936, 0.835]),
  PeachPuff: fromRgb([1, 0.855, 0.725]),
  Peru: fromRgb([0.804, 0.52, 0.248]),
  Pink: fromRgb([1, 0.752, 0.796]),
  Plum: fromRgb([0.868, 0.628, 0.868]),
  PowderBlue: fromRgb([0.69, 0.88, 0.9]),
  Purple: fromRgb([0.5, 0, 0.5]),
  Red: fromRgb([1, 0, 0]),
  RosyBrown: fromRgb([0.736, 0.56, 0.56]),
  RoyalBlue: fromRgb([0.255, 0.41, 0.884]),
  SaddleBrown: fromRgb([0.545, 0.27, 0.075]),
  Salmon: fromRgb([0.98, 0.5, 0.448]),
  SandyBrown: fromRgb([0.956, 0.644, 0.376]),
  SeaGreen: fromRgb([0.18, 0.545, 0.34]),
  Seashell: fromRgb([1, 0.96, 0.932]),
  Sienna: fromRgb([0.628, 0.32, 0.176]),
  Silver: fromRgb([0.752, 0.752, 0.752]),
  SkyBlue: fromRgb([0.53, 0.808, 0.92]),
  SlateBlue: fromRgb([0.415, 0.352, 0.804]),
  SlateGray: fromRgb([0.44, 0.5, 0.565]),
  SlateGrey: fromRgb([0.44, 0.5, 0.565]),
  Snow: fromRgb([1, 0.98, 0.98]),
  SpringGreen: fromRgb([0, 1, 0.498]),
  SteelBlue: fromRgb([0.275, 0.51, 0.705]),
  Tan: fromRgb([0.824, 0.705, 0.55]),
  Teal: fromRgb([0, 0.5, 0.5]),
  Thistle: fromRgb([0.848, 0.75, 0.848]),
  Tomato: fromRgb([1, 0.39, 0.28]),
  Turquoise: fromRgb([0.25, 0.88, 0.815]),
  Violet: fromRgb([0.932, 0.51, 0.932]),
  VioletRed: fromRgb([0.816, 0.125, 0.565]),
  Wheat: fromRgb([0.96, 0.87, 0.7]),
  White: fromRgb([1, 1, 1]),
  WhiteSmoke: fromRgb([0.96, 0.96, 0.96]),
  Yellow: fromRgb([1, 1, 0]),
  YellowGreen: fromRgb([0.604, 0.804, 0.196])
};
const X11_NAMES = {
  AntiqueWhite1: fromRgb([1, 0.936, 0.86]),
  AntiqueWhite2: fromRgb([0.932, 0.875, 0.8]),
  AntiqueWhite3: fromRgb([0.804, 0.752, 0.69]),
  AntiqueWhite4: fromRgb([0.545, 0.512, 0.47]),
  Aquamarine1: fromRgb([0.498, 1, 0.83]),
  Aquamarine2: fromRgb([0.464, 0.932, 0.776]),
  Aquamarine3: fromRgb([0.4, 0.804, 0.668]),
  Aquamarine4: fromRgb([0.27, 0.545, 0.455]),
  Azure1: fromRgb([0.94, 1, 1]),
  Azure2: fromRgb([0.88, 0.932, 0.932]),
  Azure3: fromRgb([0.756, 0.804, 0.804]),
  Azure4: fromRgb([0.512, 0.545, 0.545]),
  Bisque1: fromRgb([1, 0.894, 0.77]),
  Bisque2: fromRgb([0.932, 0.835, 0.716]),
  Bisque3: fromRgb([0.804, 0.716, 0.62]),
  Bisque4: fromRgb([0.545, 0.49, 0.42]),
  Blue1: fromRgb([0, 0, 1]),
  Blue2: fromRgb([0, 0, 0.932]),
  Blue3: fromRgb([0, 0, 0.804]),
  Blue4: fromRgb([0, 0, 0.545]),
  Brown1: fromRgb([1, 0.25, 0.25]),
  Brown2: fromRgb([0.932, 0.23, 0.23]),
  Brown3: fromRgb([0.804, 0.2, 0.2]),
  Brown4: fromRgb([0.545, 0.136, 0.136]),
  Burlywood1: fromRgb([1, 0.828, 0.608]),
  Burlywood2: fromRgb([0.932, 0.772, 0.57]),
  Burlywood3: fromRgb([0.804, 0.668, 0.49]),
  Burlywood4: fromRgb([0.545, 0.45, 0.332]),
  CadetBlue1: fromRgb([0.596, 0.96, 1]),
  CadetBlue2: fromRgb([0.556, 0.898, 0.932]),
  CadetBlue3: fromRgb([0.48, 0.772, 0.804]),
  CadetBlue4: fromRgb([0.325, 0.525, 0.545]),
  Chartreuse1: fromRgb([0.498, 1, 0]),
  Chartreuse2: fromRgb([0.464, 0.932, 0]),
  Chartreuse3: fromRgb([0.4, 0.804, 0]),
  Chartreuse4: fromRgb([0.27, 0.545, 0]),
  Chocolate1: fromRgb([1, 0.498, 0.14]),
  Chocolate2: fromRgb([0.932, 0.464, 0.13]),
  Chocolate3: fromRgb([0.804, 0.4, 0.112]),
  Chocolate4: fromRgb([0.545, 0.27, 0.075]),
  Coral1: fromRgb([1, 0.448, 0.336]),
  Coral2: fromRgb([0.932, 0.415, 0.312]),
  Coral3: fromRgb([0.804, 0.356, 0.27]),
  Coral4: fromRgb([0.545, 0.244, 0.185]),
  Cornsilk1: fromRgb([1, 0.972, 0.864]),
  Cornsilk2: fromRgb([0.932, 0.91, 0.804]),
  Cornsilk3: fromRgb([0.804, 0.785, 0.694]),
  Cornsilk4: fromRgb([0.545, 0.532, 0.47]),
  Cyan1: fromRgb([0, 1, 1]),
  Cyan2: fromRgb([0, 0.932, 0.932]),
  Cyan3: fromRgb([0, 0.804, 0.804]),
  Cyan4: fromRgb([0, 0.545, 0.545]),
  DarkGoldenrod1: fromRgb([1, 0.725, 0.06]),
  DarkGoldenrod2: fromRgb([0.932, 0.68, 0.055]),
  DarkGoldenrod3: fromRgb([0.804, 0.585, 0.048]),
  DarkGoldenrod4: fromRgb([0.545, 0.396, 0.03]),
  DarkOliveGreen1: fromRgb([0.792, 1, 0.44]),
  DarkOliveGreen2: fromRgb([0.736, 0.932, 0.408]),
  DarkOliveGreen3: fromRgb([0.635, 0.804, 0.352]),
  DarkOliveGreen4: fromRgb([0.43, 0.545, 0.24]),
  DarkOrange1: fromRgb([1, 0.498, 0]),
  DarkOrange2: fromRgb([0.932, 0.464, 0]),
  DarkOrange3: fromRgb([0.804, 0.4, 0]),
  DarkOrange4: fromRgb([0.545, 0.27, 0]),
  DarkOrchid1: fromRgb([0.75, 0.244, 1]),
  DarkOrchid2: fromRgb([0.698, 0.228, 0.932]),
  DarkOrchid3: fromRgb([0.604, 0.196, 0.804]),
  DarkOrchid4: fromRgb([0.408, 0.132, 0.545]),
  DarkSeaGreen1: fromRgb([0.756, 1, 0.756]),
  DarkSeaGreen2: fromRgb([0.705, 0.932, 0.705]),
  DarkSeaGreen3: fromRgb([0.608, 0.804, 0.608]),
  DarkSeaGreen4: fromRgb([0.41, 0.545, 0.41]),
  DarkSlateGray1: fromRgb([0.592, 1, 1]),
  DarkSlateGray2: fromRgb([0.552, 0.932, 0.932]),
  DarkSlateGray3: fromRgb([0.475, 0.804, 0.804]),
  DarkSlateGray4: fromRgb([0.32, 0.545, 0.545]),
  DeepPink1: fromRgb([1, 0.08, 0.576]),
  DeepPink2: fromRgb([0.932, 0.07, 0.536]),
  DeepPink3: fromRgb([0.804, 0.064, 0.464]),
  DeepPink4: fromRgb([0.545, 0.04, 0.312]),
  DeepSkyBlue1: fromRgb([0, 0.75, 1]),
  DeepSkyBlue2: fromRgb([0, 0.698, 0.932]),
  DeepSkyBlue3: fromRgb([0, 0.604, 0.804]),
  DeepSkyBlue4: fromRgb([0, 0.408, 0.545]),
  DodgerBlue1: fromRgb([0.116, 0.565, 1]),
  DodgerBlue2: fromRgb([0.11, 0.525, 0.932]),
  DodgerBlue3: fromRgb([0.094, 0.455, 0.804]),
  DodgerBlue4: fromRgb([0.064, 0.305, 0.545]),
  Firebrick1: fromRgb([1, 0.19, 0.19]),
  Firebrick2: fromRgb([0.932, 0.172, 0.172]),
  Firebrick3: fromRgb([0.804, 0.15, 0.15]),
  Firebrick4: fromRgb([0.545, 0.1, 0.1]),
  Gold1: fromRgb([1, 0.844, 0]),
  Gold2: fromRgb([0.932, 0.79, 0]),
  Gold3: fromRgb([0.804, 0.68, 0]),
  Gold4: fromRgb([0.545, 0.46, 0]),
  Goldenrod1: fromRgb([1, 0.756, 0.145]),
  Goldenrod2: fromRgb([0.932, 0.705, 0.132]),
  Goldenrod3: fromRgb([0.804, 0.608, 0.112]),
  Goldenrod4: fromRgb([0.545, 0.41, 0.08]),
  Green1: fromRgb([0, 1, 0]),
  Green2: fromRgb([0, 0.932, 0]),
  Green3: fromRgb([0, 0.804, 0]),
  Green4: fromRgb([0, 0.545, 0]),
  Honeydew1: fromRgb([0.94, 1, 0.94]),
  Honeydew2: fromRgb([0.88, 0.932, 0.88]),
  Honeydew3: fromRgb([0.756, 0.804, 0.756]),
  Honeydew4: fromRgb([0.512, 0.545, 0.512]),
  HotPink1: fromRgb([1, 0.43, 0.705]),
  HotPink2: fromRgb([0.932, 0.415, 0.655]),
  HotPink3: fromRgb([0.804, 0.376, 0.565]),
  HotPink4: fromRgb([0.545, 0.228, 0.385]),
  IndianRed1: fromRgb([1, 0.415, 0.415]),
  IndianRed2: fromRgb([0.932, 0.39, 0.39]),
  IndianRed3: fromRgb([0.804, 0.332, 0.332]),
  IndianRed4: fromRgb([0.545, 0.228, 0.228]),
  Ivory1: fromRgb([1, 1, 0.94]),
  Ivory2: fromRgb([0.932, 0.932, 0.88]),
  Ivory3: fromRgb([0.804, 0.804, 0.756]),
  Ivory4: fromRgb([0.545, 0.545, 0.512]),
  Khaki1: fromRgb([1, 0.965, 0.56]),
  Khaki2: fromRgb([0.932, 0.9, 0.52]),
  Khaki3: fromRgb([0.804, 0.776, 0.45]),
  Khaki4: fromRgb([0.545, 0.525, 0.305]),
  LavenderBlush1: fromRgb([1, 0.94, 0.96]),
  LavenderBlush2: fromRgb([0.932, 0.88, 0.898]),
  LavenderBlush3: fromRgb([0.804, 0.756, 0.772]),
  LavenderBlush4: fromRgb([0.545, 0.512, 0.525]),
  LemonChiffon1: fromRgb([1, 0.98, 0.804]),
  LemonChiffon2: fromRgb([0.932, 0.912, 0.75]),
  LemonChiffon3: fromRgb([0.804, 0.79, 0.648]),
  LemonChiffon4: fromRgb([0.545, 0.536, 0.44]),
  LightBlue1: fromRgb([0.75, 0.936, 1]),
  LightBlue2: fromRgb([0.698, 0.875, 0.932]),
  LightBlue3: fromRgb([0.604, 0.752, 0.804]),
  LightBlue4: fromRgb([0.408, 0.512, 0.545]),
  LightCyan1: fromRgb([0.88, 1, 1]),
  LightCyan2: fromRgb([0.82, 0.932, 0.932]),
  LightCyan3: fromRgb([0.705, 0.804, 0.804]),
  LightCyan4: fromRgb([0.48, 0.545, 0.545]),
  LightGoldenrod1: fromRgb([1, 0.925, 0.545]),
  LightGoldenrod2: fromRgb([0.932, 0.864, 0.51]),
  LightGoldenrod3: fromRgb([0.804, 0.745, 0.44]),
  LightGoldenrod4: fromRgb([0.545, 0.505, 0.298]),
  LightPink1: fromRgb([1, 0.684, 0.725]),
  LightPink2: fromRgb([0.932, 0.635, 0.68]),
  LightPink3: fromRgb([0.804, 0.55, 0.585]),
  LightPink4: fromRgb([0.545, 0.372, 0.396]),
  LightSalmon1: fromRgb([1, 0.628, 0.48]),
  LightSalmon2: fromRgb([0.932, 0.585, 0.448]),
  LightSalmon3: fromRgb([0.804, 0.505, 0.385]),
  LightSalmon4: fromRgb([0.545, 0.34, 0.26]),
  LightSkyBlue1: fromRgb([0.69, 0.888, 1]),
  LightSkyBlue2: fromRgb([0.644, 0.828, 0.932]),
  LightSkyBlue3: fromRgb([0.552, 0.712, 0.804]),
  LightSkyBlue4: fromRgb([0.376, 0.484, 0.545]),
  LightSteelBlue1: fromRgb([0.792, 0.884, 1]),
  LightSteelBlue2: fromRgb([0.736, 0.824, 0.932]),
  LightSteelBlue3: fromRgb([0.635, 0.71, 0.804]),
  LightSteelBlue4: fromRgb([0.43, 0.484, 0.545]),
  LightYellow1: fromRgb([1, 1, 0.88]),
  LightYellow2: fromRgb([0.932, 0.932, 0.82]),
  LightYellow3: fromRgb([0.804, 0.804, 0.705]),
  LightYellow4: fromRgb([0.545, 0.545, 0.48]),
  Magenta1: fromRgb([1, 0, 1]),
  Magenta2: fromRgb([0.932, 0, 0.932]),
  Magenta3: fromRgb([0.804, 0, 0.804]),
  Magenta4: fromRgb([0.545, 0, 0.545]),
  Maroon1: fromRgb([1, 0.204, 0.7]),
  Maroon2: fromRgb([0.932, 0.19, 0.655]),
  Maroon3: fromRgb([0.804, 0.16, 0.565]),
  Maroon4: fromRgb([0.545, 0.11, 0.385]),
  MediumOrchid1: fromRgb([0.88, 0.4, 1]),
  MediumOrchid2: fromRgb([0.82, 0.372, 0.932]),
  MediumOrchid3: fromRgb([0.705, 0.32, 0.804]),
  MediumOrchid4: fromRgb([0.48, 0.215, 0.545]),
  MediumPurple1: fromRgb([0.67, 0.51, 1]),
  MediumPurple2: fromRgb([0.624, 0.475, 0.932]),
  MediumPurple3: fromRgb([0.536, 0.408, 0.804]),
  MediumPurple4: fromRgb([0.365, 0.28, 0.545]),
  MistyRose1: fromRgb([1, 0.894, 0.884]),
  MistyRose2: fromRgb([0.932, 0.835, 0.824]),
  MistyRose3: fromRgb([0.804, 0.716, 0.71]),
  MistyRose4: fromRgb([0.545, 0.49, 0.484]),
  NavajoWhite1: fromRgb([1, 0.87, 0.68]),
  NavajoWhite2: fromRgb([0.932, 0.81, 0.63]),
  NavajoWhite3: fromRgb([0.804, 0.7, 0.545]),
  NavajoWhite4: fromRgb([0.545, 0.475, 0.37]),
  OliveDrab1: fromRgb([0.752, 1, 0.244]),
  OliveDrab2: fromRgb([0.7, 0.932, 0.228]),
  OliveDrab3: fromRgb([0.604, 0.804, 0.196]),
  OliveDrab4: fromRgb([0.41, 0.545, 0.132]),
  Orange1: fromRgb([1, 0.648, 0]),
  Orange2: fromRgb([0.932, 0.604, 0]),
  Orange3: fromRgb([0.804, 0.52, 0]),
  Orange4: fromRgb([0.545, 0.352, 0]),
  OrangeRed1: fromRgb([1, 0.27, 0]),
  OrangeRed2: fromRgb([0.932, 0.25, 0]),
  OrangeRed3: fromRgb([0.804, 0.215, 0]),
  OrangeRed4: fromRgb([0.545, 0.145, 0]),
  Orchid1: fromRgb([1, 0.512, 0.98]),
  Orchid2: fromRgb([0.932, 0.48, 0.912]),
  Orchid3: fromRgb([0.804, 0.41, 0.79]),
  Orchid4: fromRgb([0.545, 0.28, 0.536]),
  PaleGreen1: fromRgb([0.604, 1, 0.604]),
  PaleGreen2: fromRgb([0.565, 0.932, 0.565]),
  PaleGreen3: fromRgb([0.488, 0.804, 0.488]),
  PaleGreen4: fromRgb([0.33, 0.545, 0.33]),
  PaleTurquoise1: fromRgb([0.732, 1, 1]),
  PaleTurquoise2: fromRgb([0.684, 0.932, 0.932]),
  PaleTurquoise3: fromRgb([0.59, 0.804, 0.804]),
  PaleTurquoise4: fromRgb([0.4, 0.545, 0.545]),
  PaleVioletRed1: fromRgb([1, 0.51, 0.67]),
  PaleVioletRed2: fromRgb([0.932, 0.475, 0.624]),
  PaleVioletRed3: fromRgb([0.804, 0.408, 0.536]),
  PaleVioletRed4: fromRgb([0.545, 0.28, 0.365]),
  PeachPuff1: fromRgb([1, 0.855, 0.725]),
  PeachPuff2: fromRgb([0.932, 0.796, 0.68]),
  PeachPuff3: fromRgb([0.804, 0.688, 0.585]),
  PeachPuff4: fromRgb([0.545, 0.468, 0.396]),
  Pink1: fromRgb([1, 0.71, 0.772]),
  Pink2: fromRgb([0.932, 0.664, 0.72]),
  Pink3: fromRgb([0.804, 0.57, 0.62]),
  Pink4: fromRgb([0.545, 0.39, 0.424]),
  Plum1: fromRgb([1, 0.732, 1]),
  Plum2: fromRgb([0.932, 0.684, 0.932]),
  Plum3: fromRgb([0.804, 0.59, 0.804]),
  Plum4: fromRgb([0.545, 0.4, 0.545]),
  Purple1: fromRgb([0.608, 0.19, 1]),
  Purple2: fromRgb([0.57, 0.172, 0.932]),
  Purple3: fromRgb([0.49, 0.15, 0.804]),
  Purple4: fromRgb([0.332, 0.1, 0.545]),
  Red1: fromRgb([1, 0, 0]),
  Red2: fromRgb([0.932, 0, 0]),
  Red3: fromRgb([0.804, 0, 0]),
  Red4: fromRgb([0.545, 0, 0]),
  RosyBrown1: fromRgb([1, 0.756, 0.756]),
  RosyBrown2: fromRgb([0.932, 0.705, 0.705]),
  RosyBrown3: fromRgb([0.804, 0.608, 0.608]),
  RosyBrown4: fromRgb([0.545, 0.41, 0.41]),
  RoyalBlue1: fromRgb([0.284, 0.464, 1]),
  RoyalBlue2: fromRgb([0.264, 0.43, 0.932]),
  RoyalBlue3: fromRgb([0.228, 0.372, 0.804]),
  RoyalBlue4: fromRgb([0.152, 0.25, 0.545]),
  Salmon1: fromRgb([1, 0.55, 0.41]),
  Salmon2: fromRgb([0.932, 0.51, 0.385]),
  Salmon3: fromRgb([0.804, 0.44, 0.33]),
  Salmon4: fromRgb([0.545, 0.298, 0.224]),
  SeaGreen1: fromRgb([0.33, 1, 0.624]),
  SeaGreen2: fromRgb([0.305, 0.932, 0.58]),
  SeaGreen3: fromRgb([0.264, 0.804, 0.5]),
  SeaGreen4: fromRgb([0.18, 0.545, 0.34]),
  Seashell1: fromRgb([1, 0.96, 0.932]),
  Seashell2: fromRgb([0.932, 0.898, 0.87]),
  Seashell3: fromRgb([0.804, 0.772, 0.75]),
  Seashell4: fromRgb([0.545, 0.525, 0.51]),
  Sienna1: fromRgb([1, 0.51, 0.28]),
  Sienna2: fromRgb([0.932, 0.475, 0.26]),
  Sienna3: fromRgb([0.804, 0.408, 0.224]),
  Sienna4: fromRgb([0.545, 0.28, 0.15]),
  SkyBlue1: fromRgb([0.53, 0.808, 1]),
  SkyBlue2: fromRgb([0.494, 0.752, 0.932]),
  SkyBlue3: fromRgb([0.424, 0.65, 0.804]),
  SkyBlue4: fromRgb([0.29, 0.44, 0.545]),
  SlateBlue1: fromRgb([0.512, 0.435, 1]),
  SlateBlue2: fromRgb([0.48, 0.404, 0.932]),
  SlateBlue3: fromRgb([0.41, 0.35, 0.804]),
  SlateBlue4: fromRgb([0.28, 0.235, 0.545]),
  SlateGray1: fromRgb([0.776, 0.888, 1]),
  SlateGray2: fromRgb([0.725, 0.828, 0.932]),
  SlateGray3: fromRgb([0.624, 0.712, 0.804]),
  SlateGray4: fromRgb([0.424, 0.484, 0.545]),
  Snow1: fromRgb([1, 0.98, 0.98]),
  Snow2: fromRgb([0.932, 0.912, 0.912]),
  Snow3: fromRgb([0.804, 0.79, 0.79]),
  Snow4: fromRgb([0.545, 0.536, 0.536]),
  SpringGreen1: fromRgb([0, 1, 0.498]),
  SpringGreen2: fromRgb([0, 0.932, 0.464]),
  SpringGreen3: fromRgb([0, 0.804, 0.4]),
  SpringGreen4: fromRgb([0, 0.545, 0.27]),
  SteelBlue1: fromRgb([0.39, 0.72, 1]),
  SteelBlue2: fromRgb([0.36, 0.675, 0.932]),
  SteelBlue3: fromRgb([0.31, 0.58, 0.804]),
  SteelBlue4: fromRgb([0.21, 0.392, 0.545]),
  Tan1: fromRgb([1, 0.648, 0.31]),
  Tan2: fromRgb([0.932, 0.604, 0.288]),
  Tan3: fromRgb([0.804, 0.52, 0.248]),
  Tan4: fromRgb([0.545, 0.352, 0.17]),
  Thistle1: fromRgb([1, 0.884, 1]),
  Thistle2: fromRgb([0.932, 0.824, 0.932]),
  Thistle3: fromRgb([0.804, 0.71, 0.804]),
  Thistle4: fromRgb([0.545, 0.484, 0.545]),
  Tomato1: fromRgb([1, 0.39, 0.28]),
  Tomato2: fromRgb([0.932, 0.36, 0.26]),
  Tomato3: fromRgb([0.804, 0.31, 0.224]),
  Tomato4: fromRgb([0.545, 0.21, 0.15]),
  Turquoise1: fromRgb([0, 0.96, 1]),
  Turquoise2: fromRgb([0, 0.898, 0.932]),
  Turquoise3: fromRgb([0, 0.772, 0.804]),
  Turquoise4: fromRgb([0, 0.525, 0.545]),
  VioletRed1: fromRgb([1, 0.244, 0.59]),
  VioletRed2: fromRgb([0.932, 0.228, 0.55]),
  VioletRed3: fromRgb([0.804, 0.196, 0.47]),
  VioletRed4: fromRgb([0.545, 0.132, 0.32]),
  Wheat1: fromRgb([1, 0.905, 0.73]),
  Wheat2: fromRgb([0.932, 0.848, 0.684]),
  Wheat3: fromRgb([0.804, 0.73, 0.59]),
  Wheat4: fromRgb([0.545, 0.494, 0.4]),
  Yellow1: fromRgb([1, 1, 0]),
  Yellow2: fromRgb([0.932, 0.932, 0]),
  Yellow3: fromRgb([0.804, 0.804, 0]),
  Yellow4: fromRgb([0.545, 0.545, 0]),
  Gray0: fromRgb([0.745, 0.745, 0.745]),
  Green0: fromRgb([0, 1, 0]),
  Grey0: fromRgb([0.745, 0.745, 0.745]),
  Maroon0: fromRgb([0.69, 0.19, 0.376]),
  Purple0: fromRgb([0.628, 0.125, 0.94])
};
const parseCache = {};
function parse(str = "") {
  parseCache[str] = parseCache[str] || unifiedLatexUtilPegjs.XColorPegParser.parse(str);
  return parseCache[str];
}
const CORE_MODELS = /* @__PURE__ */ new Set(["rgb", "cmy", "cmyk", "hsb", "gray"]);
const XColorCoreModelToColor = {
  rgb: ([r, g, b]) => Color([r * 255, g * 255, b * 255], "rgb"),
  cmy: ([c, m, y]) => XColorCoreModelToColor.rgb([1 - c, 1 - m, 1 - y]),
  cmyk: ([c, m, y, k]) => Color([c * 255, m * 255, y * 255, k * 100], "cmyk"),
  hsb: ([h, s, b]) => Color([h * 360, s * 100, b * 100], "hsv"),
  gray: ([v]) => Color([v * 255, v * 255, v * 255], "rgb")
};
const XColorModelToColor = {
  wave: ([lambda]) => {
    const gamma = 0.8;
    let baseRgb = [0, 0, 0];
    if (380 <= lambda && lambda < 440) {
      baseRgb = [(440 - lambda) / (440 - 380), 0, 1];
    }
    if (440 <= lambda && lambda < 490) {
      baseRgb = [0, (lambda - 440) / (490 - 440), 1];
    }
    if (490 <= lambda && lambda < 510) {
      baseRgb = [0, 1, (510 - lambda) / (510 - 490)];
    }
    if (510 <= lambda && lambda < 580) {
      baseRgb = [(lambda - 510) / (580 - 510), 1, 0];
    }
    if (580 <= lambda && lambda < 6450) {
      baseRgb = [1, (645 - lambda) / (645 - 580), 0];
    }
    if (645 <= lambda && lambda <= 780) {
      baseRgb = [1, 0, 0];
    }
    let f = 1;
    if (380 <= lambda && 420 < lambda) {
      f = 0.3 + 0.7 * (lambda - 380) / (420 - 380);
    }
    if (700 < lambda && lambda <= 780) {
      f = 0.3 + 0.7 * (780 - lambda) / (780 - 700);
    }
    const rgb = [
      Math.pow(baseRgb[0] * f, gamma),
      Math.pow(baseRgb[1] * f, gamma),
      Math.pow(baseRgb[2] * f, gamma)
    ];
    return Color([rgb[0] * 255, rgb[1] * 255, rgb[2] * 255], "rgb");
  },
  Hsb: ([h, s, b]) => XColorCoreModelToColor.hsb([h / 360, s, b]),
  HSB: ([h, s, b]) => XColorCoreModelToColor.hsb([h / 240, s / 240, b / 240]),
  HTML: ([v]) => v.startsWith("#") ? Color(v) : Color(`#${v}`),
  RGB: ([r, g, b]) => Color([r, g, b], "rgb"),
  Gray: ([v]) => XColorCoreModelToColor.gray([v / 15]),
  ...XColorCoreModelToColor
};
const ColorToXColorModel = {
  rgb: (color) => color.rgb().array().map((v) => v / 255),
  cmy: (color) => [255 - color.red(), 255 - color.green(), 255 - color.blue()].map(
    (v) => v / 255
  ),
  cmyk: (color) => color.cmyk().array().map((v, i) => i === 3 ? v / 100 : v / 255),
  hsb: (color) => [
    color.hue() / 360,
    color.saturationv() / 100,
    color.value() / 100
  ],
  gray: (color) => [color.gray() / 100]
};
const PREDEFINED_XCOLOR_COLORS = {
  // Core colors
  red: XColorCoreModelToColor.rgb([1, 0, 0]),
  green: XColorCoreModelToColor.rgb([0, 1, 0]),
  blue: XColorCoreModelToColor.rgb([0, 0, 1]),
  brown: XColorCoreModelToColor.rgb([0.75, 0.5, 0.25]),
  lime: XColorCoreModelToColor.rgb([0.75, 1, 0]),
  orange: XColorCoreModelToColor.rgb([1, 0.5, 0]),
  pink: XColorCoreModelToColor.rgb([1, 0.75, 0.75]),
  purple: XColorCoreModelToColor.rgb([0.75, 0, 0.25]),
  teal: XColorCoreModelToColor.rgb([0, 0.5, 0.5]),
  violet: XColorCoreModelToColor.rgb([0.5, 0, 0.5]),
  cyan: XColorCoreModelToColor.rgb([0, 1, 1]),
  magenta: XColorCoreModelToColor.rgb([1, 0, 1]),
  yellow: XColorCoreModelToColor.rgb([1, 1, 0]),
  olive: XColorCoreModelToColor.rgb([0.5, 0.5, 0]),
  black: XColorCoreModelToColor.rgb([0, 0, 0]),
  darkgray: XColorCoreModelToColor.rgb([0.25, 0.25, 0.25]),
  gray: XColorCoreModelToColor.rgb([0.5, 0.5, 0.5]),
  lightgray: XColorCoreModelToColor.rgb([0.75, 0.75, 0.75]),
  white: XColorCoreModelToColor.rgb([1, 1, 1]),
  ...DVI_PS_NAMES,
  ...SVG_NAMES,
  ...X11_NAMES
};
function scalarMul(scalar, vec) {
  return vec.map((v) => scalar * v);
}
function addVectors(...vecs) {
  return vecs.reduce((prev, current) => prev.map((v, i) => v + current[i]));
}
function mixInModel(model, colorsAndCoefficients) {
  if (!CORE_MODELS.has(model)) {
    throw new Error(
      `Cannot mix colors in model "${model}"; only core modes ${Array.from(
        CORE_MODELS
      ).join(", ")} are supported`
    );
  }
  const toModel = ColorToXColorModel[model];
  const fromModel = XColorCoreModelToColor[model];
  const mixed = addVectors(
    ...colorsAndCoefficients.map(([v, color]) => {
      const colorInModel = toModel(color);
      return scalarMul(v, colorInModel);
    })
  );
  return fromModel(mixed);
}
function computeColor(expr, predefinedColors = {}) {
  if (expr.type !== "color") {
    throw new Error(
      `Can only compute the color of a "color" expression, not one of type ${expr.type}`
    );
  }
  const knownColors = { ...PREDEFINED_XCOLOR_COLORS, ...predefinedColors };
  function getColor(name) {
    if (!knownColors[name]) {
      throw new Error(`Unknown color "${name}"`);
    }
    return knownColors[name];
  }
  const color = expr.color;
  let computedColor = Color("#000000");
  if (color.type === "expr") {
    let base = getColor(color.name);
    for (const mix of color.mix_expr) {
      if (mix.type === "complete_mix") {
        const mixColor = getColor(mix.name);
        base = base.mix(mixColor, 1 - mix.mix_percent / 100);
      } else if (mix.type === "partial_mix") {
        base = base.mix(Color("#FFFFFF"), 1 - mix.mix_percent / 100);
      }
    }
    if (color.prefix && color.prefix.length % 2 === 1) {
      base = base.rotate(180);
    }
    computedColor = base;
  }
  if (color.type === "extended_expr") {
    const model = color.core_model;
    const div = color.div || color.expressions.reduce((a, expr2) => a + expr2.weight, 0);
    if (div <= 0) {
      throw new Error(
        `Cannot mix color with ratios that have a denominator of ${div}`
      );
    }
    const colorsToMix = color.expressions.map(
      (expr2) => [
        expr2.weight / div,
        computeColor({
          type: "color",
          color: expr2.color,
          functions: []
        })
      ]
    );
    computedColor = mixInModel(model, colorsToMix);
  }
  for (const func of expr.functions) {
    if (func.name === "wheel") {
      const angle = func.args[0];
      const circ = func.args[1] || 360;
      computedColor = computedColor.rotate(angle / circ * 360);
    }
    if (func.name === "twheel") {
      const angle = func.args[0];
      const circ = func.args[1] || 360;
      computedColor = computedColor.rotate(angle / circ * 360 + 60);
    }
  }
  return computedColor;
}
function xcolorColorToHex(color, model, options = { predefinedColors: {} }) {
  const { predefinedColors = {} } = options;
  const parsed = parse(color);
  if (model && model !== "default" && parsed.type !== "color") {
    if (!(model in XColorModelToColor)) {
      throw new Error(
        `Unknown color model "${model}"; known models are ${Object.keys(
          XColorModelToColor
        ).join(", ")}`
      );
    }
    if (parsed.type !== "hex_spec" && parsed.type !== "num_spec") {
      throw new Error(
        `Cannot use model ${model} to compute the color "${color}"`
      );
    }
    if (model === "HTML" && parsed.type === "hex_spec") {
      return XColorModelToColor.HTML(parsed.content).hex();
    } else if (parsed.type === "num_spec") {
      return XColorModelToColor[model](parsed.content).hex();
    }
    throw new Error(
      `Don't know how to process color "${color}" in model "${model}"`
    );
  }
  if (Array.isArray(parsed) || parsed.type !== "color") {
    throw new Error(
      `Cannot the color "${color}" is not a valid color string`
    );
  }
  let computed = null;
  try {
    computed = computeColor(parsed, predefinedColors);
  } catch (e) {
  }
  return computed && computed.hex();
}
exports.DVI_PS_NAMES = DVI_PS_NAMES;
exports.PREDEFINED_XCOLOR_COLORS = PREDEFINED_XCOLOR_COLORS;
exports.SVG_NAMES = SVG_NAMES;
exports.X11_NAMES = X11_NAMES;
exports.XColorCoreModelToColor = XColorCoreModelToColor;
exports.computeColor = computeColor;
exports.environments = environments;
exports.macros = macros;
exports.parse = parse;
exports.xcolorColorToHex = xcolorColorToHex;
//# sourceMappingURL=xcolor-BEfsW_1K.cjs.map
