Import Processing sketch code into InDesign, while keeping colour and indentation formatting

Hi,

I'm making a folio in InDesign of all the Processing sketches I made this semester for uni and I'm wondering if there is an efficient way to keep the formatting and indentation?

At the moment I'm using GREP styles, but it's starting to get cumbersome when I add all the words that Processing changes to a colour, like "random", "height", "dist", "if", "pushMatrix" etc. See image below:

GREP_question

I found a forum post from 2014 (see link) where someone suggested printing to PDF from Processing and then placing the PDF in InDesign. However, I'd prefer to have the text actually inside InDesign so I can control how it flows across pages.

In the same post @Chrisir suggested exporting as HTML. However, I can't find out how to import HTML into InDesign. I can only find out how to export HTML from InDesign.

Ultimately, I would like to be able to annotate my Processing sketches like in the Generative Design book edited by Claudius Lazzeroni:

Formatting_Processing_Code

Thanks in advance for any advice,
Matthew

Tagged:

Answers

  • If you can use latex in your document, then this next post can be useful: https://forum.processing.org/two/discussion/comment/103660/#Comment_103660

    Not sure if this is applicable in your case. Could you clarify, what type of formatting does InDesign use?

    Kf

  • edited October 2017 Answer ✓

    Thanks @kfrajer ,

    I hadn't heard of LaTeX before, but I was able to adapt the work that @ebigunso had done to build GREP rules that would format the text in InDesign. The following csv contains the GREP rules (Thanks @ebigunso for laying the groundwork!):

    type,colourName,colourHex,fontStyle,GREP
    keyword_1_2_6,bluegreen,#33997e,Regular,\babstract\b|\bbreak\b|\bclass\b|\bcontinue\b|\bdefault\b|\benum\b|\bextends\b|\bfalse\b|\bfinal\b|\bfinally\b|\bimplements\b|\bimport\b|\binstanceof\b|\binterface\b|\bnative\b|\bnew\b|\bnull\b|\bpackage\b|\bprivate\b|\bprotected\b|\bpublic\b|\bstatic\b|\bstrictfp\b|\bthrows\b|\btransient\b|\btrue\b|\bvoid\b|\bvolatile\b|\blength\b|\bassert\b|\bcase\b|\breturn\b|\bsuper\b|\bthis\b|\bthrow\b
    keyword_3,lightgreen,#669900,Regular,\bcatch\b|\bdo\b|\bfor\b|\bif\b|\belse\b|\bswitch\b|\bsynchronized\b|\bwhile\b|\btry\b
    keyword_4,magenta,#d94a7a,Regular,width\b|\bheight\b|\bpixelHight\b|\bdisplayHeight\b|\bdisplayWidth\b|\bfocused\b|\bframeCount\b|\bframeRate\b|\bkey\b|\bkeyCode\b|\bkeyPressed\b|\bmouseButton\b|\bmousePressed\b|\bmouseX\b|\bmouseY\b|\bpixels\b|\bpixelWidth\b|\bpmouseX\b|\bpmouseY
    keyword_5,orange,#e2661a,Regular,\bArray\b|\bArrayList\b|\bBoolean\b|\bByte\b|\bBufferedReader\b|\bCharacter\b|\bClass\b|\bDouble\b|\bFloat\b|\bInteger\b|\bHashMap\b|\bPrintWriter\b|\bString\b|\bStringBuffer\b|\bStringBuilder\b|\bThread\b|\bboolean\b|\bbyte\b|\bchar\b|\bcolor\b|\bdouble\b|\bfloat\b|\bint\b|\blong\b|\bshort\b|\bFloatDict\b|\bFloatList\b|\bIntDict\b|\bIntList\b|\bJSONArray\b|\bJSONObject\b|\bPFont\b|\bPGraphics\b|\bPImage\b|\bPShader\b|\bPShape\b|\bPVector\b|\bStringDict\b|\bStringList\b|\bTable\b|\bTableRow\b|\bXML\b
    literal_2,green,#718a62,Regular,(ADD\b|\bALIGN_CENTER\b|\bALIGN_LEFT\b|\bALIGN_RIGHT\b|\bALPHA\b|\bALPHA_MASK\b|\bALT\b|\bAMBIENT\b|\bARC\b|\bARROW\b|\bARGB\b|\bBACKSPACE\b|\bBASELINE\b|\bBEVEL\b|\bBLEND\b|\bBLUE_MASK\b|\bBLUR\b|\bBOTTOM\b|\bBOX\b|\bBURN\b|\bCENTER\b|\bCHATTER\b|\bCHORD\b|\bCLAMP\b|\bCLICK\b|\bCLOSE\b|\bCMYK\b|\bCODED\b|\bCOMPLAINT\b|\bCOMPOSITE\b|\bCOMPONENT\b|\bCONCAVE_POLYGON\b|\bCONTROL\b|\bCONVEX_POLYGON\b|\bCORNER\b|\bCORNERS\b|\bCROSS\b|\bCUSTOM\b|\bDARKEST\b|\bDEGREES\b|\bDEG_TO_RAD\b|\bDELETE\b|\bDIAMETER\b|\bDIFFERENCE\b|\bDIFFUSE\b|\bDILATE\b|\bDIRECTIONAL\b|\bDISABLE_ACCURATE_2D\b|\bDISABLE_DEPTH_MASK\b|\bDISABLE_DEPTH_SORT\b|\bDISABLE_DEPTH_TEST\b|\bDISABLE_NATIVE_FONTS\b|\bDISABLE_OPENGL_ERRORS\b|\bDISABLE_PURE_STROKE\b|\bDISABLE_TEXTURE_MIPMAPS\b|\bDISABLE_TRANSFORM_CACHE\b|\bDISABLE_STROKE_PERSPECTIVE\b|\bDISABLED\b|\bDODGE\b|\bDOWN\b|\bDRAG\b|\bDXF\b|\bELLIPSE\b|\bENABLE_ACCURATE_2D\b|\bENABLE_DEPTH_MASK\b|\bENABLE_DEPTH_SORT\b|\bENABLE_DEPTH_TEST\b|\bENABLE_NATIVE_FONTS\b|\bENABLE_OPENGL_ERRORS\b|\bENABLE_PURE_STROKE\b|\bENABLE_TEXTURE_MIPMAPS\b|\bENABLE_TRANSFORM_CACHE\b|\bENABLE_STROKE_PERSPECTIVE\b|\bENTER\b|\bEPSILON\b|\bERODE\b|\bESC\b|\bEXCLUSION\b|\bEXIT\b|\bFX2D\b|\bGIF\b|\bGRAY\b|\bGREEN_MASK\b|\bGROUP\b|\bHALF\b|\bHALF_PI\b|\bHAND\b|\bHARD_LIGHT\b|\bHINT_COUNT\b|\bHSB\b|\bIMAGE\b|\bINVERT\b|\bJAVA2D\b|\bJPEG\b|\bLEFT\b|\bLIGHTEST\b|\bLINE\b|\bLINES\b|\bLINUX\b|\bMACOSX\b|\bMAX_FLOAT\b|\bMAX_INT\b|\bMIN_FOAT\b|\bMIN_INT\b|\bMITER\b|\bMODEL\b|\bMOVE\b|\bMULTIPLY\b|\bNORMAL\b|\bNORMALIZED\b|\bNO_DEPTH_TEST\b|\bNTSC\b|\bONE\b|\bOPAQUE\b|\bOPEN\b|\bORTHOGRAPHIC\b|\bOVERLAY\b|\bPAL\b|\bPDF\b|\bP2D\b|\bP3D\b|\bPERSPECTIVE\b|\bPI\b|\bPIE\b|\bPIXEL_CENTER\b|\bPOINT\b|\bPOINTS\b|\bPOSTERIZE\b|\bPRESS\b|\bPROBLEM\b|\bPROJECT\b|\bQUAD\b|\bQUAD_STRIP\b|\bQUADS\b|\bQUARTER_PI\b|\bRAD_TO_DEG\b|\bRADIUS\b|\bRADIANS\b|\bRECT\b|\bRED_MASK\b|\bRELEASE\b|\bREPEAT\b|\bREPLACE\b|\bRETURN\b|\bRGB\b|\bRIGHT\b|\bROUND\b|\bSCREEN\b|\bSECAM\b|\bSHAPE\b|\bSHIFT\b|\bSPAN\b|\bSPECULAR\b|\bSPHERE\b|\bSOFT_LIGHT\b|\bSQUARE\b|\bSUBTRACT\b|\bSVG\b|\bSVIDEO\b|\bTAB\b|\bTARGA\b|\bTAU\b|\bTEXT\b|\bTFF\b|\bTHIRD_PI\b|\bTHRESHOLD\b|\bTIFF\b|\bTOP\b|\bTRIANGLE\b|\bTRIANGLE_FAN\b|\bTRIANGLES\b|\bTRIANGLE_STRIP\b|\bTUNER\b|\bTWO\b|\bTWO_PI\b|\bUP\b|\bWAIT\b|\bWHITESPACE)
    function_1,lightblue,#006699,Regular,\bstart\b|\bstop\b|\bbreakShape\b|\bcreatePath\b|\bstr\b|\bloadMatrix\b|\bparseBoolean\b|\bparseByte\b|\bparseChar\b|\bparseFloat\b|\bparseInt\b|\bsaveFile\b|\bsavePath\b|\bsketchFile\b|\bsketchPath\b|\babs\b|\bacos\b|\balpha\b|\bambient\b|\bambientLight\b|\bappend\b|\bapplyMatrix\b|\barc\b|\barrayCopy\b|\basin\b|\batan\b|\batan2\b|\bbackground\b|\bbeginCamera\b|\bbeginContour\b|\bbeginRaw\b|\bbeginRecord\b|\bbeginShape\b|\bbezier\b|\bbezierDetail\b|\bbezierPoint\b|\bbezierTangent\b|\bbezierVertex\b|\bbinary\b|\bblend\b|\bblendColor\b|\bblendMode\b|\bblue\b|\bbox\b|\bbrightness\b|\bcamera\b|\bceil\b|\bclear\b|\bclip\b|\bcolor\b|\bcolorMode\b|\bconcat\b|\bconstrain\b|\bcopy\b|\bcos\b|\bcreateFont\b|\bcreateGraphics\b|\bcreateImage\b|\bcreateInput\b|\bcreateOutput\b|\bcreateReader\b|\bcreateShape\b|\bcreateWriter\b|\bcursor\b|\bcurve\b|\bcurveDetail\b|\bcurvePoint\b|\bcurveTangent\b|\bcurveTightness\b|\bcurveVertex\b|\bday\b|\bdegrees\b|\bdelay\b|\bdirectionalLight\b|\bdisplayDensity\b|\bdist\b|\bellipse\b|\bellipseMode\b|\bemissive\b|\bendCamera\b|\bendContour\b|\bendRaw\b|\bendRecord\b|\bendShape\b|\bexit\b|\bexp\b|\bexpand\b|\bfill\b|\bfilter\b|\bfloor\b|\bfrustum\b|\bfullScreen\b|\bget\b|\bgreen\b|\bhex\b|\bhint\b|\bhour\b|\bhue\b|\bimage\b|\bimageMode\b|\bjoin\b|\blaunch\b|\blerp\b|\blerpColor\b|\blightFalloff\b|\blights\b|\blightSpecular\b|\bline\b|\bloadBytes\b|\bloadFont\b|\bloadImage\b|\bloadJSONArray\b|\bloadJSONObject\b|\bloadPixels\b|\bloadShader\b|\bloadShape\b|\bloadStrings\b|\bloadTable\b|\bloadXML\b|\blog\b|\bloop\b|\bmag\b|\bmap\b|\bmatch\b|\bmatchAll\b|\bmax\b|\bmillis\b|\bmin\b|\bminute\b|\bmodelX\b|\bmodelY\b|\bmodelZ\b|\bmonth\b|\bnf\b|\bnfc\b|\bnfp\b|\bnfs\b|\bnoClip\b|\bnoCursor\b|\bnoFill\b|\bnoise\b|\bnoiseDetail\b|\bnoiseSeed\b|\bnoLights\b|\bnoLoop\b|\bnorm\b|\bnormal\b|\bnoSmooth\b|\bnoStroke\b|\bnoTint\b|\bortho\b|\bparseJSONArray\b|\bparseJSONObject\b|\bparseXML\b|\bperspective\b|\blist\b|\bpixelDnsity\b|\bpoint\b|\bpointLight\b|\bpopMatrix\b|\bpopStyle\b|\bpow\b|\bprint\b|\bprintArray\b|\bprintCamera\b|\bprintln\b|\bprintMatrix\b|\bprintProjection\b|\bpushMatrix\b|\bpushStyle\b|\bquad\b|\bquadraticVertex\b|\bradians\b|\brandom\b|\brandomGaussian\b|\brandomSeed\b|\brect\b|\brectMode\b|\bred\b|\bredraw\b|\brequestImage\b|\bresetMatrix\b|\bresetShader\b|\breverse\b|\brotate\b|\brotateX\b|\brotateY\b|\brotateZ\b|\bround\b|\bsaturation\b|\bsave\b|\bsaveBytes\b|\bsaveFrame\b|\bsaveJSONArray\b|\bsaveJSONObject\b|\bsaveStream\b|\bsaveStrings\b|\bsaveTable\b|\bsaveXML\b|\bscale\b|\bscreenX\b|\bscreenY\b|\bscreenZ\b|\bsecond\b|\bselectFolder\b|\bselectInput\b|\bselectOutput\b|\bset\b|\bshader\b|\bshape\b|\bshapeMode\b|\bshearX\b|\bshearY\b|\bshininess\b|\bshorten\b|\bsin\b|\bsize\b|\bsmooth\b|\bsort\b|\bspecular\b|\bsphere\b|\bsphereDetail\b|\bsplice\b|\bsplit\b|\bsplitTokens\b|\bspotLight\b|\bsq\b|\bsqrt\b|\bstroke\b|\bstrokeCap\b|\bstrokeJoin\b|\bstrokeWeight\b|\bsubset\b|\btan\b|\btext\b|\btextAlign\b|\btextAscent\b|\btextDescent\b|\btextFont\b|\btextLeading\b|\btextMode\b|\btextSize\b|\btexture\b|\btextureMode\b|\btextureWrap\b|\btextWidth\b|\bthread\b|\btint\b|\btranslate\b|\btriangle\b|\btrim\b|\bunbinary\b|\bunhex\b|\bupdatePixels\b|\bvertex\b|\byear\b|\bcache\b|\breadLine\b|\bclose\b|\bflush\b|\bprint\b|\bprintln\b|\bcharAt\b|\bequals\b|\bindexOf\b|\bsubstring\b|\btoLowerCase\b|\btoUpperCase\b|\bgetDouble\b|\bgetLong\b|\bgetColumnTitles\b|\bgetColumnTypes\b|\bgetColumnType\b|\bsetDouble\b|\bsetLong\b|\badd\b|\bclear\b|\bdiv\b|\bget\b|\bhasKey\b|\bkeyArray\b|\bkeys\b|\bmult\b|\bremove\b|\bset\b|\bsize\b|\bsortKeys\b|\bsortKeysReverse\b|\bsortValues\b|\bsortValuesReverse\b|\bsub\b|\bvalueArray\b|\bvalues\b|\bappend\b|\barray\b|\bhasValue\b|\bmax\b|\bmin\b|\bmult\b|\bremove\b|\breverse\b|\bshuffle\b|\bsort\b|\bsortReverse\b|\bincrement\b|\bgetBoolean\b|\bgetFloat\b|\bgetInt\b|\bgetIntArray\b|\bgetJSONArray\b|\bgetJSONObject\b|\bgetString\b|\bgetStringArray\b|\bisNull\b|\bsetBoolean\b|\bsetFloat\b|\bsetInt\b|\bsetJSONArray\b|\bsetJSONObject\b|\bsetString\b|\bbeginDraw\b|\bendDraw\b|\bblend\b|\bcopy\b|\bfilter\b|\bloadPixels\b|\bmask\b|\bresize\b|\bsave\b|\bupdatePixels\b|\baddChild\b|\bbeginContour\b|\bbeginShape\b|\bdisableStyle\b|\benableStyle\b|\bendContour\b|\bendShape\b|\bgetChild\b|\bgetChildCount\b|\bgetVertex\b|\bgetVertexCount\b|\bisVisible\b|\bresetMatrix\b|\brotate\b|\brotateX\b|\brotateY\b|\brotateZ\b|\bscae\b|\bsetFill\b|\bsetStroke\b|\bsetVertex\b|\bsetVisible\b|\btranslate\b|\bangleBetween\b|\bcross\b|\bdist\b|\bdot\b|\bfromAngle\b|\bheading\b|\blerp\b|\blimit\b|\bmag\b|\bmagSq\b|\bnormalize\b|\brandm2D\b|\brandom3D\b|\bsetMag\b|\blower\b|\bupper\b|\baddColumn\b|\baddRow\b|\bclearRows\b|\bfindRow\b|\bfindRows\b|\bgetColumnCount\b|\bgetRow\b|\bgetRowcount\b|\bgetStringColumn\b|\bmatchRow\b|\bmatchRows\b|\bremoveColumn\b|\bremoveRow\b|\bremoveTokens\b|\brows\b|\btrim\b|\bgetColumnTitle\b|\bformat\b|\bgetAttributeCount\b|\bgetChildren\b|\bgetContent\b|\bgetNam\b|\bgetParent\b|\bhasAttribute\b|\bhasChildren\b|\blistAttributes\b|\blistChildren\b|\bremoveChild\b|\bsetContent\b|\bsetName\b|\btoString\b
    function_4,lightblue,#006699,Bold,draw(?=\()|keyReleased(?=\()|keyTyped(?=\()|mouseClicked(?=\()|mouseDragged(?=\()|mouseMoved(?=\()|mouseReleased(?=\()|mouseWheel(?=\()|settings(?=\()|setup(?=\()
    string,purple,#7D4793,Regular,(?<=").*?(?=")
    

    If anyone is interested here are the steps in InDesign:

    Step 1. Open 'Paragraph Style Options'

    Grep_1

    Step 2. Select 'GREP Style' from the list on the left.

    Step 3. Click 'New GREP Style'

    Step 4. Click 'Apply Style:' and from the drop down menu click 'New Character Style'

    Grep_2

    Step 5. Change the character 'Style Name:' to the first item in the csv row e.g. "keyword_1_2_6_bluegreen"

    Step 6. Select 'Character Color' from the list on the left.

    Step 7. Add a new colour swatch and paste the hex colour from the csv row e.g. "33997e"

    Step 8. Back in the "GREP Style" window of "Paragraph Style Options" paste the GREP item from csv row into the "To Text:" field:

    \babstract\b|\bbreak\b|\bclass\b|\bcontinue\b|\bdefault\b|\benum\b|\bextends\b|\bfalse\b|\bfinal\b|\bfinally\b|\bimplements\b|\bimport\b|\binstanceof\b|\binterface\b|\bnative\b|\bnew\b|\bnull\b|\bpackage\b|\bprivate\b|\bprotected\b|\bpublic\b|\bstatic\b|\bstrictfp\b|\bthrows\b|\btransient\b|\btrue\b|\bvoid\b|\bvolatile\b|\blength\b|\bassert\b|\bcase\b|\breturn\b|\bsuper\b|\bthis\b|\bthrow\b

    Step 9. Repeat all steps for each row in the csv

    Please note there are two issues with this approach:

    1. InDesign seems to put a limit on the number of GREP styles so I wasn't able add purple formatting to strings.

    2. This is the first time I've used GREP, so I haven't worked out how to do other formatting like change code that had been commented out with "//" to grey.

    Any tips on improving how Processing sketches can be represented in InDesign would be very much appreciated.

    Thanks, Matthew

  • @Matthew_K

    I am glad to hear the post helped. This cannot go without saying, thxs for sharing your solution and your detailed steps. I have one more question for you. Could you comment a little bit about InDesign? Is it use for actual code formatting or also as a publishing tool?

    Kf

  • InDesign is Adobe's desktop publishing application -- the Microsoft Word of desktop publishing. It isn't particularly for code -- it is for everything: "posters, flyers, brochures, magazines, newspapers, presentations, books and ebooks"

  • @jeremydouglass Thxs for the info.

    Kf

Sign In or Register to comment.