% -*- latex -*-

% Program listings need to be typeset
\usepackage{color}
\usepackage[final]{listings}

% We have lots of chapters and lots of listings. Thus, the table of listings at the beginning of the book needs more space for the number. This LaTeX magic comes from https://tex.stackexchange.com/questions/107047/lstlistoflistings-doesnt-have-enough-room-between-numbers-and-title
\makeatletter
\def\l@lstlisting#1#2{\@dottedtocline{1}{1.5em}{3em}{#1}{#2}}
\makeatother

\definecolor{vtkmidentifier}{rgb}{0,0,1}
\definecolor{vtkmnamespace}{rgb}{0.5,0,0}
\definecolor{vtkmmacro}{rgb}{0.5,0,0}
\definecolor{vtkmsignature}{rgb}{0,0.5,0}
\definecolor{codebackground}{rgb}{0.95,0.95,0.95}

\lstloadlanguages{C,C++}
%% \lstset{fontadjust=false,basicstyle=\scriptsize\ttfamily}
\lstset{fontadjust=false,basicstyle=\footnotesize\ttfamily,
        xleftmargin=3em, xrightmargin=3em,
        numbers=left, numberstyle=\footnotesize, numbersep=1em,
        belowcaptionskip=0pt,  %Prevents caption from being on different page.
        frame=l, backgroundcolor=\color{codebackground},
        escapechar=@}
\lstdefinelanguage{VTKm}{
  morekeywords={struct,class,public,typedef,using,typename,void,template,return,operator,const,for,int,float,double},
  morekeywords={[2]Id,Id2,Id3,Id4,
                   IdComponent,IdComponent2,IdComponent3,IdComponent4,Vec,
                   Int8,Int16,Int32,Int64,UInt8,UInt16,UInt32,UInt64,
                   Float32,Float64,FloatDefault,
                   BufferSizeType,
                   make_Id3,make_Vec,
                   Dot,NUM_COMPONENTS,
                   VecC,VecCConst,make_VecC,
                   VecFromPortal,VecFromPortalPermute,
                   VecRectilinearPointCoordinates,
                   VecVariable,
                   Vec2f,Vec3f,Vec4f,
                   Vec2i,Vec3i,Vec4i,
                   Vec2ui,Vec3ui,Vec4ui,
                   Vec2f_64,Vec3f_64,Vec4f_64,
                   Vec2i_64,Vec3i_64,Vec4i_64,
                   Vec2ui_64,Vec3ui_64,Vec4ui_64,
                   Vec2f_32,Vec3f_32,Vec4f_32,
                   Vec2i_32,Vec3i_32,Vec4i_32,
                   Vec2ui_32,Vec3ui_32,Vec4ui_32,
                   Vec2i_16,Vec3i_16,Vec4i_16,
                   Vec2ui_16,Vec3ui_16,Vec4ui_16,
                   Vec2i_8,Vec3i_8,Vec4i_8,
                   Vec2ui_8,Vec3ui_8,Vec4ui_8,
                   Extent,Extent3,Pair,
                   Range,Bounds,
                   Tuple,MakeTuple,TupleSize,TupleElement,Get,
                   Initialize,InitializeResult,InitializeOptions,
                   SetStderrLogLevel,SetLogLevelName,GetLogLevelName,LogLevel,
                   GetStackTrace,GetHumanReadableSize,GetSizeString,
                   TypeToString,SetThreadName,GetThreadName,
                   ExtentPointDimensions,ExtentCellDimensions,
                   ExtentNumberOfPoints,ExtentNumberOfCells,
                   ExtentPointFlatIndexToTopologyIndex,
                   ExtentCellFlatIndexToTopologyIndex,
                   ExtentPointTopologyIndexToFlatIndex,
                   ExtentCellTopologyIndexToFlatIndex,
                   ExtentFirstPointOnCell,
                   ListEmpty,ListUniversal,
                   List,
                   ListSize,ListHas,ListIndexOf,ListAt,
                   ListAppend,ListIntersect,
                   ListRemoveIf,
                   ListCross,
                   ListForEach,
                   TypeListId,TypeListId2,TypeListId3,
                   TypeListIndex,
                   TypeListFieldScalar,TypeListScalarAll,
                   TypeListFieldVec2,
                   TypeListFieldVec3,
                   TypeListFieldVec4,
                   TypeListField,
                   TypeListVecCommon,TypeListVecAll,
                   TypeListAll,TypeListCommon,
                   IsZeroInitialized,NotZeroInitialized,LogicalNot,
                   Equal,NotEqual,SortLess,SortGreater,LogicalAnd,LogicalOr,
                   Sum,Product,Maximum,Minimum,MinAndMax,
                   BitwiseAnd,BitwiseOr,BitwiseXor,
                   WorkletBase,
                   WorkletMapField,
                   WorkletMapTopology,
                   WorkletVisitCellsWithPoints,
                   WorkletVisitPointsWithCells,
                   WorkletPointNeighborhood,
                   WorkletReduceByKey,
                   Invoker,
                   DispatcherMapField,
                   DispatcherMapTopology,
                   DispatcherPointNeighborhood,
                   DispatcherReduceByKey,
                   ScatterIdentity,
                   ScatterUniform,
                   ScatterCounting,
                   Keys,
                   ExecutionObjectBase,
                   AverageByKey,
                   TypeTraits,NumericTag,DimensionalityTag,
                   TypeTraitsRealTag,TypeTraitsIntegerTag,
                   TypeTraitsScalarTag,TypeTraitsVectorTag,
                   VecTraits,ComponentType,HasMultipleComponents,
                   IsSizeStatic,VecTraitsTagSizeStatic,VecTraitsTagSizeVariable,
                   VecTraitsTagMultipleComponents,
                   VecTraitsTagSingleComponent,
                   Error,ErrorExecution,
                   ErrorBadAllocation,
                   ErrorBadType,
                   ErrorBadValue,
                   ErrorInternal,
                   DeviceAdapterTagSerial,
                   DeviceAdapterTagCuda,
                   DeviceAdapterTagOpenMP,
                   DeviceAdapterTagTBB,
                   DeviceAdapterTagKokkos,
                   DeviceAdapterTagAny,
                   DeviceAdapterTagUnknown,
                   DeviceAdapterId,
                   DeviceAdapterNameType,
                   RuntimeDeviceTracker,GetRuntimeDeviceTracker,
                   ScopedRuntimeDeviceTracker,RuntimeDeviceTrackerMode,
                   TryExecute,
                   CellDataToPointDataGenerateKeys,
                   CellDataToPointDataReduceKeys,
                   CellGradient,
                   Cosine,Sine,Magnitude,Square,
                   Elevation,
                   FieldToColors,
                   PointDataToCellData,
                   SliceClassify,SliceGenerate,
                   Streamline,
                   LagrangianStructures,
                   Tetrahedralize,
                   ThresholdClassify,ThresholdTopology,
                   ClipWithImplicitFunction,ClipWithField,
                   ArrayHandle,make_ArrayHandle,CopyFlag,
                   make_ArrayHandleMove,
                   ArrayHandleBasic,
                   ArrayHandleCast,make_ArrayHandleCast,
                   ArrayHandleCompositeVector,make_ArrayHandleCompositeVector,
                   ArrayHandleCompositeVectorType,
                   ArrayHandleConstant,make_ArrayHandleConstant,
                   ArrayHandleCounting,make_ArrayHandleCounting,
                   ArrayHandleDiscard,
                   ArrayHandleExtractComponent,make_ArrayHandleExtractComponent,
                   ArrayHandleGroupVec,make_ArrayHandleGroupVec,
                   ArrayHandleGroupVecVariable,make_ArrayHandleGroupVecVariable,
                   ConvertNumComponentsToOffsets,
                   ArrayHandleImplicit,make_ArrayHandleImplicit,
                   ArrayHandleIndex,
                   ArrayHandleTransform,make_ArrayHandleTransform,
                   ArrayHandleSOA,make_ARrayHandleSOA,
                   ArrayHandleSwizzle,make_ArrayHandleSwizzle,
                   ArrayHandlePermutation,make_ArrayHandlePermutation,
                   ArrayHandleZip,make_ArrayHandleZip,
                   ArrayHandleUniformPointCoordinates,
                   ArrayHandleCartesianProduct,make_ArrayHandleCartesianProduct,
                   ArrayHandleVirtual,
                   ArrayPortalToIterators,
                   ArrayPortalToIteratorBegin,ArrayPortalToIteratorEnd,
                   ArrayCopy,
                   ArrayRangeCompute,
                   AtomicArray,AtomicArrayExecutionObject,
                   Buffer,
                   MakeBuffer,
                   CreateBuffers,
                   Storage,
                   StorageTagBasic,
                   StorageTagImplicit,
                   StorageTagSOA,
                   Token,
                   ArrayContainerControl,
                   ArrayContainerControlTagBasic,
                   ArrayContainerControlTagImplicit,
                   ArrayTransfer,
                   DeviceAdapterMemoryManager,DeviceAdapterMemoryManagerBase,
                   DeviceAdapterMemoryManagerBase,
                   DeviceAdapterMemoryManagerShared,
                   VirtualObjectTransfer,
                   VirtualObjectTransferShareWithControl,
                   VariantArrayHandle,VariantArrayHandleBase,
                   Timer,
                   DataSet,
                   PartitionedDataSet,
                   BoundsCompute,
                   BoundsGlobalCompute,
                   FieldRangeCompute,
                   FieldRangeGlobalCompute,
                   CellSet,
                   CellSetExplicit,
                   CellSetPermutation,
                   CellSetSingleType,
                   CellSetStructured,
                   CellSetListCommon,
                   CellSetListStructured,CellSetListUnstructured,
                   DynamicCellSet,
                   Field,
                   CoordinateSystem,
                   DataSetBuilderExplicit,DataSetBuilderExplicitIterative,
                   DataSetBuilderRectilinear,
                   DataSetBuilderUniform,
                   ConvertNumIndicesToOffsets,
                   CellLocator,CellLocatorGeneral,
                   CellLocatorUniformGrid,CellLocatorRectilinearGrid,
                   CellLocatorTwoLevel,CellLocatorBoundingIntervalHierarchy,
                   PointLocator,
                   PointLocatorSparseGrid,
                   FilterDataSet,
                   FilterDataSetWithField,
                   FilterField,
                   FieldMetadata,
                   FilterTraits,
                   FieldSelection,
                   CreateResult,CreateResultFieldPoint,CreateResultFieldCell,
                   PolicyBase,
                   PolicyDefault,
                   ApplyPolicyFieldNotActive,ApplyPolicyFieldActive,
                   ApplyPolicyFieldOfType,ApplyPolicyCellSet,
                   ApplyPolicyCellSetStructured,ApplyPolicyCellSetUnstructured,
                   CellAverage,
                   PointAverage,
                   ExternalFaces,
                   Contour,
                   PointElevation,
                   CleanGrid,
                   Threshold,
                   VertexClustering,
                   Streamline,Particle,
                   StreamSurface,Pathline,
                   MeshQuality,CellMetric,
                   Actor,
                   AxisAnnotation, AxisAnnotation2D, AxisAnnotation3D,
                   BitmapFont, BitmapFontFactory,
                   BoundingBoxAnnotation,
                   Camera,
                   Canvas,
                   CanvasGL,
                   CanvasOSMesa,
                   CanvasRayTracer,
                   Color,
                   ColorBarAnnotation,
                   ColorTable,
                   MatrixHelpers,
                   Scene,
                   Mapper,
                   MapperConenctivity,
                   MapperGL,
                   MapperRayTracer,
                   MapperVolume,
                   MapperWireframer,
                   TextAnnotation,
                   Triangulator,
                   View,View1D,View2D,View3D,
                   WorldAnnotator, WorldAnnotatorGL,
                   DeviceAdapterAlgorithm, DeviceAdapterAlgorithmGeneral,
                   Algorithm,
                   DeviceAdapterTimerImplementation,
                   IteratorFromArrayPortal,
                   TypeCheck,TypeCheckTagExecObject,
                   TypeCheckTagArrayIn,TypeCheckTagArrayInOut,
                   TypeCheckTagArrayOut,
                   TypeCheckTagAtomicArray,
                   TransportTagBitFieldIn,TransportTagBitFieldInOut,
                   TransportTagBitFieldInOut,
                   TypeCheckTagCellSet,TypeCheckTagCellSetStructured,
                   TypeCheckTagBitField,
                   TypeCheckTagExecObject,
                   TypeCheckTagKeys,
                   Transport,
                   TransportTagArrayIn,TransportTagArrayOut,
                   TransportTagArrayInOut,
                   TransportTagExecObject,
                   TransportTagWholeArrayIn,TransportTagWholeArrayOut,
                   TransportTagWholeArrayInOut,
                   TransportTagAtomicArray,
                   TransportTagCellSetIn,TransportTagTopologyFieldIn,
                   TransportTagKeysIn,
                   TransportTagKeyedValuesIn,TransportTagKeyedValuesOut,
                   TransportTagKeyedValuesInOut,
                   TransportTagReducedValuesIn,
                   Fetch,
                   FetchTagArrayDirectIn,FetchTagArrayDirectOut,
                   FetchTagExecObject,
                   FetchtagCellSetIn,FetchTagArrayTopologyMapIn,
                   AspectTagDefault,
                   AspectTagWorkIndex,AspectTagOutputIndex,
                   AspectTagVisitIndex,
                   AspectTagCellShape,
                   AspectTagIncidentElementCount,
                   AspectTagIncidentElementIndices,
                   AspectTagValueCount,
                   ControlSignatureTagBase,ExecutionSignatureTagBase,
                   Invocation,
                   FunctionInterface,make_FunctionInterface,
                   FunctionInterfaceReturnContainer,
                   DynamicTransform,
                   CellField, CellVertices,
                   InterpolatedCellPoints,
                   CellTraits,NUM_VERTICES,
                   CellTagHexahedron, CellTagLine, CellTagQuadrilateral,
                   CellTagTetrahedron, CellTagTriangle, CellTagVectex,
                   CellTagVoxel, CellTagWedge,
                   CellTraits,
                   CellTopologicalDimensionsTag,
                   GridTagUniform, GridTagUnstructured,
                   NUM_VERTICES, TOPOLOGICAL_DIMENSIONS,
                   ParametricCoordinates, CellDerivative,
                   SortLess, SortGreater,
                   Max, Min,
                   Cbrt, Exp, Exp10, Exp2, ExpM1, Log, Log10, Log1P, Log2,
                   Pow, RCbrt, RSqrt, Sqrt,
                   Matrix, Matrix2x2, Matrix3x3, Matrix4x4,
                   MatrixColumn, MatrixDeterminant, MatrixIdentity,
                   MatrixInverse, MatrixMultiply, MatrixRow,
                   MatrixSetColumn, MatrixSetRow, MatrixTranspose,
                   SolveLinearSystem,
                   NewtonsMethod,NewtonsMethodResult,
                   Ceil, Epsilon, Floor, FMod, Infinity, IsFinite, IsInf,
                   IsNan, ModF, Nan, NegativeInfinity, Remainder,
                   RemainderQuotient, Round,
                   Abs, CopySign, IsNegative, SignBit,
                   ACos, ACosH, ASin, ASinH, ATan, ATan2, ATanH, Cos, CosH,
                   Pi, Sin, SinH, Tan, TanH,
                   Cross, Magnitude, MagnitudeSquared, Lerp, Normal,
                   Normalize, RMagnitude, TriangleNormal,
                   ImplicitFunction,
                   Box,Cylinder,Frustum,Plane,Sphere,
                   ImplicitFunctionHandle,make_ImplicitFunctionHandle
                   CellShapeTagEmpty,
                   CellShapeTagVertex,
                   CellShapeTagLine,
                   CellShapeTagTriangle,
                   CellShapeTagPolygon,
                   CellShapeTagQuad,
                   CellShapeTagTetra,
                   CellShapeTagHexahedron,
                   CellShapeTagWedge,
                   CellShapeTagPyramid,
                   CellShapeTagGeneric,
                   CellShapeIdToTag,
                   CELL_SHAPE_EMPTY,
                   CELL_SHAPE_VERTEX,
                   CELL_SHAPE_LINE,
                   CELL_SHAPE_TRIANGLE,
                   CELL_SHAPE_POLYGON,
                   CELL_SHAPE_QUAD,
                   CELL_SHAPE_TETRA,
                   CELL_SHAPE_HEXAHEDRON,
                   CELL_SHAPE_WEDGE,
                   CELL_SHAPE_PYRAMID,
                   CellTraits,
                   CellTopologicalDimensionsTag,
                   CellTraitsTagSizeFixed,
                   CellTraitsTagSizeVariable,
                   ParametricCoordinatesToWorldCoordinates,
                   WorldCoordinatesToParametricCoordinates,
                   ParametricCoordinatesCenter,
                   ParametricCoordinatesPoint,
                   CellInterpolate,
                   CellDerivative,
                   CellEdgeNumberOfEdges,CellEdgeLocalIndex,
                   CellEdgeCanonicalId,
                   CellFaceNumberOfFaces,CellFaceNumberOfPoints,
                   CellFaceLocalIndex,CellFaceCanonicalId,
                   Hash,HashType,
                   ErrorCode,ErrorString,
                   TransferToOpenGL,
                   TopologyElementTagCell,
                   TopologyElementTagPoint,
                   TopologyElementTagEdge,
                   TopologyElementTagFace,
                   FieldNeighborhood,BoundaryState,
                   VTKDataSetReader,VTKDataSetWriter,
                   ImageReaderBase,ImageReaderPNG,ImageReaderPNM,
                   ImageWriterBase,ImageWriterPNG,ImageWriterPNM,
                   PixelDepth
                   },
  morekeywords={[3]VTKM_CONT,VTKM_EXEC,VTKM_EXEC_CONT,
                   VTKM_LOG_S,VTKM_LOG_F,VTKM_LOG_IF_S,VTKM_LOG_IF_F,
                   VTKM_LOG_SCOPE,VTKM_LOG_SCOPE_FUNCTION,
                   VTKM_LOG_ERROR_CONTEXT,
                   VTKM_SUPPRESS_EXEC_WARNINGS,
                   VTKM_DEVICE_ADAPTER,
                   VTKM_DEVICE_ADAPTER_SERIAL,
                   VTKM_DEVICE_ADAPTER_CUDA,
                   VTKM_DEVICE_ADAPTER_OPENMP,
                   VTKM_DEVICE_ADAPTER_TBB,
                   VTKM_DEVICE_ADAPTER_ERROR,
                   VTKM_DEFAULT_DEVICE_ADAPTER_TAG,
                   VTKM_STORAGE,
                   VTKM_STORAGE_BASIC,
                   VTKM_STORAGE_ERROR,
                   VTKM_STORAGE_UNDEFINED,
                   VTKM_DEFAULT_STORAGE_TAG,
                   VTKM_ARRAY_HANDLE_SUBCLASS,VTKM_ARRAY_HANDLE_SUBCLASS_NT,
                   VTKM_ASSERT,VTKM_STATIC_ASSERT,VTKM_STATIC_ASSERT_MSG,
                   VTKM_DEFAULT_TYPE_LIST,
                   VTKM_DEFAULT_STORAGE_LIST,
                   VTKM_DEFAULT_CELL_SET_LIST,
                   VTKM_DEFAULT_CELL_SET_LIST_STRUCTURED,
                   VTKM_DEFAULT_CELL_SET_LIST_UNSTRUCTURED,
                   VTKM_DEFAULT_CONTAINER_LIST,
                   VTKM_DEFAULT_POINT_COORDINATES_LIST,
                   VTKM_VALID_DEVICE_ADAPTER,
                   VTKM_INVALID_DEVICE_ADAPTER,
                   VTKM_IS_DEVICE_ADAPTER_TAG,
                   VTKM_IS_ARRAY_HANDLE,
                   VTKM_IS_LIST,
                   VTKM_STORAGE_NO_RESIZE,VTKM_STORAGE_NO_WRITE_PORTAL,
                   vtkmGenericCellShapeMacro
                   },
  morekeywords={[4]vtkm,exec,cont,worklet,math,arg,internal,detail,
                   io,reader,writer,
                   filter,
                   rendering,
                   cuda,openmp,tbb},
  morekeywords={[5]ControlSignature,ExecutionSignature,
                   InputDomain,
                   ScatterType,
                   FieldIn,FieldOut,FieldInOut,
                   FieldInVisit,FieldInIncident,
                   FieldInPoint,FieldOutPoint,FieldInOutPoint,
                   FieldInCell,FieldOutCell,FieldInOutCell,
                   FieldInNeighborhood,
                   Boundary,
                   CellSetIn,
                   KeysIn,
                   ValuesIn,ValuesInOut,ValuesOut,
                   ReducedValuesIn,ReducedValuesInOut,ReducedValuesOut,
                   WholeArrayIn,WholeArrayOut,WholeArrayInOut,
                   AtomicArrayInOut,
                   WholeCellSetIn,
                   ExecObject,
                   WorkIndex,VisitIndex,InputIndex,OutputIndex,ThreadIndices,
                   ThreadIndices,
                   CellShape,
                   IncidentElementCount,PointCount,CellCount,
                   IncidentElementIndices,PointIndices,CellIndices,
                   OnBoundary,
                   SupportedTypes,
                   _1,_2,_3,_4,_5,_6,_7,_8,_9
                   }
}
\lstset{language=VTKm}
\lstset{
  keywordstyle=\bfseries,
  keywordstyle=[2]\color{vtkmidentifier},
  keywordstyle=[3]\color{vtkmmacro},
  keywordstyle=[4]\color{vtkmnamespace},
  keywordstyle=[5]\color{vtkmsignature}
}

\renewcommand{\lstlistlistingname}{List of Examples}
\renewcommand{\lstlistingname}{Example}

\newcommand*{\textcode}[1]{\textnormal{\texttt{#1}}}
\newcommand*{\textnamespace}[1]{\textcode{\color{vtkmnamespace}{#1}}}
\newcommand*{\textmacro}[1]{\textcode{\color{vtkmmacro}{#1}}}
\newcommand*{\textidentifier}[1]{\textcode{\color{vtkmidentifier}{#1}}}
\newcommand*{\textmethod}[1]{\textcode{#1}}
\newcommand*{\textsignature}[1]{\textcode{\color{vtkmsignature}{#1}}}

\newcommand*{\vtkmmacro}[1]{\textmacro{#1}\index{#1}}

\newcommand{\vtkmcontmodifier}{\vtkmmacro{VTKM\_CONT}\index{modifier!control}\index{function modifier}\index{method modifier}\xspace}
\newcommand{\vtkmexecmodifier}{\vtkmmacro{VTKM\_EXEC}\index{modifier!execution}\index{function modifier}\index{method modifier}\xspace}
\newcommand{\vtkmexeccontmodifier}{\vtkmmacro{VTKM\_EXEC\_CONT}\index{modifier!control}\index{modifier!execution}\index{function modifier}\index{method modifier}\xspace}

\newcommand{\controlsignature}{\textsignature{ControlSignature}\index{control signature}\index{signature!control}\xspace}
\newcommand{\executionsignature}{\textsignature{ExecutionSignature}\index{execution signature}\index{signature!execution}\xspace}
\newcommand{\inputdomain}{\textsignature{InputDomain}\index{input domain}\xspace}
\newcommand{\scattertype}{\textsignature{ScatterType}\index{scatter type}\xspace}

\newcommand*{\sigtag}[1]{\textsignature{#1}\index{#1}\index{signature tags!#1}}
\newcommand*{\sigtagnum}[1]{\sigtag{\_#1}}
\newcommand*{\sigtagmod}[2]{\sigtag{#1}\textcode{<}\sigtag{#2}\textcode{>}}
\newcommand*{\sigtagmodnum}[2]{\sigtag{#1}\textcode{<}\sigtagnum{#2}\textcode{>}}

\newcommand{\supportedtypes}{\textsignature{SupportedTypes}\index{supported types}\index{filter!supported types}\xspace}

\NewDocumentCommand{\WriteNamespace}{ m g g g }{%
  \textnamespace{#1}%
  \IfValueT{#2}{\textcode{:\colonhyp}\textnamespace{#2}}%
  \IfValueT{#3}{\textcode{:\colonhyp}\textnamespace{#3}}%
  \IfValueT{#4}{\textcode{:\colonhyp}\textnamespace{#4}}%
}

\NewDocumentCommand{\IndexNamespace}{ m g g g }{%
  \IfValueTF{#4}{%
    \index{#4 namespace}\index{#1::#2::#3::#4}\index{namespace!#1::#2::#3::#4}%
  }{%
    \IfValueTF{#3}{%
      \index{#3 namespace}\index{#1::#2::#3}\index{namespace!#1::#2::#3}%
    }{%
      \IfValueTF{#2}{%
        \index{#2 namespace}\index{#1::#2}\index{namespace!#1::#2}%
      }{%
        \index{#1 namespace}\index{namespace!#1}%
      }%
    }%
  }%
}

\NewDocumentCommand{\namespace}{ m g g g }{%
  \WriteNamespace{#1}{#2}{#3}{#4}\IndexNamespace{#1}{#2}{#3}{#4}
}

\NewDocumentCommand{\classmember}{ s o o o o m m }{%
  \IfBooleanF{#1}{%
    \IfValueT{#2}{%
      \WriteNamespace{#2}{#3}{#4}{#5}%
      \textcode{:\colonhyp}%
    }%
    \textidentifier{#6}\textcode{:\colonhyp}%
  }%
  \textmethod{#7}%
  \index{#6!#7}%
  \index{#7}%
}

\NewDocumentCommand{\WriteIndexNamespaceIdentifier}{ s m o o o m o }{%
  \WriteNamespace{#2}{#3}{#4}{#5}\textcode{:\colonhyp}\textidentifier{#6}%
  \index{#6}%
  \IfValueT{#7}{%
    \textcode{:\colonhyp}\textmethod{#7}%
    \index{#7}\index{#6!#7}%
  }%
  \IfBooleanT{#1}{%
    \textcode{()}%
  }%
  \xspace%
}

\NewDocumentCommand{\NamespaceImpl}{ m m o o o m o }{%
  \ifthenelse{\equal{#6}{}}{%
    % No classname/identifier given. Just write namespace
    \namespace{#2}{#3}{#4}{#5}%
  }{%
    \IfBooleanTF{#1}{%
      \WriteIndexNamespaceIdentifier*{#2}[#3][#4][#5]{#6}[#7]%
    }{%
      \WriteIndexNamespaceIdentifier{#2}[#3][#4][#5]{#6}[#7]%
    }%
  }%
}


\NewDocumentCommand{\vtkm}{smo}{\NamespaceImpl{#1}{vtkm}{#2}[#3]}
\NewDocumentCommand{\vtkminternal}{smo}{\NamespaceImpl{#1}{vtkm}[internal]{#2}[#3]}

\NewDocumentCommand{\vtkmcont}{smo}{\NamespaceImpl{#1}{vtkm}[cont]{#2}[#3]}
\NewDocumentCommand{\vtkmcontinternal}{smo}{\NamespaceImpl{#1}{vtkm}[cont][internal]{#2}[#3]}
\NewDocumentCommand{\vtkmcontarg}{smo}{\NamespaceImpl{#1}{vtkm}[cont][arg]{#2}[#3]}

\NewDocumentCommand{\vtkmexec}{smo}{\NamespaceImpl{#1}{vtkm}[exec]{#2}[#3]}
\NewDocumentCommand{\vtkmexecarg}{smo}{\NamespaceImpl{#1}{vtkm}[exec][arg]{#2}[#3]}
\NewDocumentCommand{\vtkmexecinternal}{smo}{\NamespaceImpl{#1}{vtkm}[exec][internal]{#2}[#3]}

\NewDocumentCommand{\vtkmworklet}{smo}{\NamespaceImpl{#1}{vtkm}[worklet]{#2}[#3]}
\NewDocumentCommand{\vtkmworkletinternal}{smo}{\NamespaceImpl{#1}{vtkm}[worklet][internal]{#2}[#3]}

\NewDocumentCommand{\vtkmio}{smo}{\NamespaceImpl{#1}{vtkm}[io]{#2}[#3]}

\NewDocumentCommand{\vtkmfilter}{smo}{\NamespaceImpl{#1}{vtkm}[filter]{#2}[#3]}
\NewDocumentCommand{\vtkmfilterinternal}{smo}{\NamespaceImpl{#1}{vtkm}[filter][internal]{#2}[#3]}

\NewDocumentCommand{\vtkmrendering}{smo}{\NamespaceImpl{#1}{vtkm}[rendering]{#2}[#3]}

\NewDocumentCommand{\vtkmopengl}{smo}{\NamespaceImpl{#1}{vtkm}[opengl]{#2}[#3]}

\NewDocumentCommand{\vtkmcontcuda}{smo}{\NamespaceImpl{#1}{vtkm}[cont][cuda]{#2}[#3]}
\NewDocumentCommand{\vtkmcontopenmp}{smo}{\NamespaceImpl{#1}{vtkm}[cont][openmp]{#2}[#3]}
\NewDocumentCommand{\vtkmcontserial}{smo}{\NamespaceImpl{#1}{vtkm}[cont][serial]{#2}[#3]}
\NewDocumentCommand{\vtkmconttbb}{smo}{\NamespaceImpl{#1}{vtkm}[cont][tbb]{#2}[#3]}

\newcommand*{\tparams}[1]{\textcode{<#1>}}

\newcommand*{\textfilename}[1]{\textsf{#1}}
\newcommand*{\vtkmheader}[2]{%
  \textfilename{#1\fshyp{}#2}\index{#1\fshyp#2}\index{#2}}

\newcommand*{\cmakevar}[1]{%
  \textsf{#1}%
  \index{#1}%
  \index{CMake!configuration!#1}}

\lstnewenvironment{vtkmexample}[2][-*-]{
  \lstset{caption={#2}}
  \ifthenelse{\equal{#1}{-*-}}{}{\lstset{label=#1}}
}{
}

\newcommand*{\vtkmlisting}[3][]{
  \lstinputlisting[language=VTKm, label=#1, caption={#2}]{examples/listing_#3}
}

% This is an ``odd'' identifier that comes up a lot.
\newcommand*{\Veclike}{\textidentifier{Vec}-like\xspace}

% Used for source code, shell, CMake, or other examples that are not worth
% creating a ``language'' for.
\lstnewenvironment{blankexample}[2][-*-]{
  \lstset{language={}}
  \lstset{caption={#2}}
  \lstset{escapechar=@}
  \ifthenelse{\equal{#1}{-*-}}{}{\lstset{label=#1}}
}{
}
