
\def\MM#1{\ifmmode#1\else\mbox{$#1$}\fi}

\newcommand{\tc}[1]{\MM{\underline{\smash{\mathit{#1}}}}}
\DeclareFixedFont{\secop}{T1}{pcr}{b}{it}{8}

% define a lstlanguage for secondo queries and scripts
% emph[1] are operators
% emph[2] are types
\lstdefinelanguage{secondoscript}{keywords={let, update, restore, derive, save, database,
                                            create, open, query, list algebras },
                                  morekeywords={const, value, desc, asc, group, TRUE, FALSE, fun}
                                  sensitive=true,
                                  string=[b]{"},
                                  comment=[l]{\#},
                                  emph=[1]{ ANY, ANY2, ELEMENT, ELEMENT2, GROUP, PSTREAM1, PSTREAM2, 
        STREAMELEM, STREAMELEM2, TUPLE, TUPLE2, abs, addcounter, 
        addid, addtupleid, adjacent, aggregate, aggregateB, aggregateS, 
        always, and, approximate, area, at, atinstant, atmax, atmin, atperiods, 
        atpoint, atposition, attr, attrsize, avg, bbox, bbox2d, before, between, 
        bool2int, boundary, box2d, box3d, breakpoints, bulkloadrtree, cancel, category, 
        ceil, char, circle, colordist, commonborder, components, concat, concatS, 
        connectedcomponents, constgraph, constgraphpoints, consume, contains,
        cost, count, count2, create\_duration, create\_instant, createbtree, 
        createdeleterel, createinsertrel, creatertree, createupdaterel, crossings, 
        cumulate, cut, day\_of, deftime, deletebtree, deletebyid, deletedirect, 
        deletedirectsave, deletertree, deletesearch, deletesearchsave, derivable, derivable\_new, 
        derivative, derivative\_new, dice, direction, display, distance, distribute, disturb, div, 
        dumpstream, duration2real, echo, edges, equal, equals, equalway, exactmatch, exactmatchS, 
        export, extattrsize, extdeftime, extend, extendstream, extract, exttuplesize, feed, filename, 
        filter, final, flipleft, floor, get, get\_duration, gettuples, gettuples2, gettuplesdbl, 
        getx, gety, gps, groupby, hashjoin, hashvalue, head, height, hour\_of, ifthenelse, ininterior, 
        initial, insert, insertbtree, insertrtree, insertsave, inserttuple, inserttuplesave, inside, 
        inst, instant2real, int2bool, int2real, integrate, intersection, intersection\_new, intersects, 
        intersects\_new, intstream, isempty, isgrayscale, isportrait, junctions, key, keywords, krdup, 
        ldistance, leapyear, leftrange, leftrangeS, length, like, line2region, linearize, linearize2, 
        locations, log, loop, loopa, loopb, loopjoin, loopjoinrel, loopsel, loopselect, loopselecta, 
        loopselectb, loopswitch, loopswitcha, loopswitchb, makearray, makearrayN, makemvalue, makepoint, 
        max, maxD, maxDuration, maxInstant, maxdegree, maximum, mbool2mint, mconsume, mdirection, 
        memshuffle, merge, mergediff, mergejoin, mergesec, mergeunion, millisecond\_of, min, minD, 
        minDuration, minInstant, mindegree, minimum, minus, minus\_new, minute\_of, mirror, mod, 
        month\_of, move, namedtransformstream, never, no\_components, no\_entries, no\_nodes, 
        no\_segments, nodes, nonequal, not, now, num2string, onborder, or, overlaps, p\_intersects, 
        partjoin, partjoinselect, partjoinswitch, partof, passes, pcreate, pcreate2, pdelete, 
        perimeter, periods2mint, pfeed, picturedate, pjoin1, pjoin2, placenodes, point2d, polylines, 
        pos, present, printintstream, printstream, product, project, projectextend, projectextendstream, 
        projecttransformstream, pshow, puse, put, queryrect2d, randint, randmax, randseed, range, 
        rangeS, rangevalues, rdup, real2int, realm, realstream, rect2region, rectangle2, rectangle3, 
        rectangle4, rectangle8, rectproject, reduce, relcount, relcount2, remove, rename, reverse, 
        rightrange, rightrangeS, rng\_GeneratorMaxRand, rng\_GeneratorMinRand, rng\_GeneratorName, 
        rng\_NoGenerators, rng\_binomial, rng\_exponential, rng\_flat, rng\_gaussian, rng\_geometric, 
        rng\_getMax, rng\_getMin, rng\_getSeed, rng\_getType, rng\_init, rng\_int, rng\_intN, 
        rng\_poisson, rng\_real, rng\_realpos, rng\_setSeed, rootattrsize, roottuplesize, 
        rough\_center, round, routes, sample, samplempoint, saveto, scale, second\_of, sections, 
        segments, sentences, seqinit, seqnext, setoption, setunitofdistance, setunitoftime, 
        shortestpath, shuffle, sim\_create\_trip, sim\_fillup\_mpoint, sim\_print\_params, 
        sim\_set\_dest\_params, sim\_set\_event\_params, sim\_set\_rng, sim\_trips, simpleequals, 
        simplify, single, size, sizecounters, sometimes, sort, sortarray, sortby, sortmergejoin, 
        source, spatialjoin, speed, speed\_new, sqrt, starts, subline, substr, sum, summarize, 
        symmjoin, symmproduct, symmproductextend, target, theInstant, theRange, the\_ivalue, 
        the\_mvalue, the\_unit, thedate, theday, thehour, theminute, themonth, thenetwork, theperiod, 
        thesecond, thevertex, theyear, tie, today, touchpoints, trajectory, transformstream, 
        translate, translateappend, translateappendS, treeheight, tupleid, tuplesize, 
        uint2ureal, union, union\_new, units, updatebtree, updatebyid, updatedirect, updatedirectsave, 
        updatertree, updatesearch, updatesearchsave, upper, use, use2, val, velocity, velocity\_new, 
        vertextrajectory, vertices, weekday\_of, width, windowclippingin, windowclippingout, 
        windowintersects, windowintersectsS, within, year\_of, zero },
                                  emph=[2]{ array, binfile, bool, btree, date, duration, 
                                            edge, gpoint, graph, histogram, 
        ibool, iint, instant, int, intimeregion, ipoint, ireal, istring, line, map, 
        mbool, mint, movingregion, mpoint, mreal, mrel, mstring, mtuple, network, 
        path, periods, picture, point, points, polygon, ptuple, rbool, real, rect, 
        rect3, rect4, rect8, region, rel, rint, rreal, rstring, rtree, rtree3, rtree4, 
        rtree8, string, text, tid, trel, tuple, ubool, uint, upoint, ureal, uregion, 
        ustring, vertex, xpoint, xrectangle}
                                  }
% define a style for formatting secondo commands
\definecolor{gray}{rgb}{0.5, 0.5, 0.5}
\lstdefinestyle{secondostyle}{basicstyle=\rm\small,
                              keywordstyle=\bfseries,
                              commentstyle=\color{gray}\it, 
                              stringstyle=\texttt,
                              showspaces=false,
                              showstringspaces=false,
                              emphstyle=[1]\secop,
                              emphstyle=[2]\tc,
                              upquote=false,
                              language=secondoscript}
