[{"created":"20210108152312708","text":".code-notselected{ }\n.code-selected{color:darkred;}\n.code-list {\n  margin-top:0;\n  margin-bottom:0;\n  background-color:<<colour page-background>>;\n  border:1px solid <<colour pre-border>>;\n  font-family:monospace;\n}\n\n.code-list  pre {\n  padding:0 0 0 5px;\n  margin:0;\n  border:none;\n  border-radius:unset;\n\n  background-color:unset;\n  opacity:0.6;\n}\n\n.code-list .code-selected pre{\n  opacity:1;\n  background-color:lightyellow;\n}","tags":"$:/tags/Stylesheet","title":"highlight-selected-lines/style.css","modified":"20210108152557325"},{"created":"20210108132441238","text":"\\define hslines(src, from, to, rng, language)\n<$wikify name=\"numbers\" text=<<rawlist>> >\n<$vars length={{{ [[$to$]subtract[$from$]add[1]] }}} source={{{[<__src__>is[tiddler]get[text]else<__src__>]}}}>\n<$set name=\"lines\" filter=\"[<source>splitregexp[\\n]addsuffix[ ]first[$to$]last<length>]\">\n<ol start=\"$from$\" class=\"code-list\">\n<$list filter=\"[range[$from$,$to$,1]]\" variable=num>\n<$list filter=\"[enlist<numbers>nsort[]match<num>then[code-selected]else[code-notselected]]\" variable=selectedClass>\n<$vars pos={{{ [<num>subtract[$from$]add[1]] }}} >\n<span class=<<selectedClass>> >\n<li><$codeblock code={{{ [enlist:raw<lines>nth<pos>]  }}} language=<<__language__>>/></li> \n</span>\n</$vars>\n</$list>\n</$list>\n</ol>\n</$set>\n</$vars>\n</$wikify>\n\\end\n\n\\define rng2list() {{{[range[$(start)$,$(end)$]addsuffix[ ]]}}}\n\n\\define rawlist()\n<$list filter=\"[<__rng__>split[,]split[ ]!is[blank]]\" variable=num>\n<$list filter=\"[<num>search:title[-]]\" emptyMessage=<<num>> variable=vrng>\n<$vars start= {{{ [<vrng>split[-]first[]] }}}\n       end=   {{{ [<vrng>split[-]last[]] }}} >\n\t\t\t <<rng2list>>\n</$vars>\t\t\t \n</$list>\n</$list>\n\\end","title":"highlight-selected-lines/hslines","tags":"$:/tags/Macro","modified":"20210108162030484"},{"created":"20210108152722259","text":"!! Example i\nMultiple ranges can be passed. The `hslines` find the correct line numbers.\n\n<$macrocall $name=\"wikitext-example-without-html\" \nsrc=\"\"\"<<hslines \"euler.py\" 21 32 \"8-9 18 32 23-25\" \"python\">>\n\"\"\"/>\n\n!! Example ii\nThere is no need to pass the slected line numbers in any order, `hslines` is smart to find which lines shall be stand out. Duplicated values can be detected and there no worry if a range like \"1-5 4 3-8\" is used.\n\n<$macrocall $name=\"wikitext-example-without-html\" \nsrc=\"\"\"<<hslines \"euler.py\" 1 10 \"8-9 5 1\" \"python\">>\n\"\"\"/>\n\n\n!! Example iii\nTransclude only few lines of main code and no selected lines to stand out.\n\n<$macrocall $name=\"wikitext-example-without-html\" \nsrc=\"\"\"<<hslines \"euler.py\" 8 9 language:\"python\">>\n\"\"\"/>","tags":"","title":"highlight-selected-lines/test01","modified":"20210108163312489"},{"created":"20210108155658027","text":"\\define code()\ndef euler():\n  \"\"\"Test function\"\"\"\n  a=10; b=20;\n  print(a, b)\n  return successful\n\\end\n\n!! Example i\nMultiple ranges can be passed. The `hslines` find the correct line numbers.\n\n<$macrocall $name=hslines\nsrc=<<code>> from=1 to=5 rng=\"3-4\" language=\"python\"/>\n\n!! Example ii\nAn example from Tiddlywiki script\n\n<$macrocall $name=hslines\nsrc=\"\"\"\n<$list filter=\"[tag[myTag]]\" variable>\n    <<currentTiddler>><br/>\n</$list>\n\n\"\"\"\nfrom=2 to=4 rng=\"3\" language=\"xml\"/>","tags":"","title":"highlight-selected-lines/test02","modified":"20210108163258662"},{"created":"20210108064810986","text":"# A Forward Eulwr code for solving IVPs\nimport numpy as np\nimport matplotlib.pyplot as plt\n\n# Concentration over time\nN = lambda t: N0 * np.exp(-k * t)\n# dN/dt\ndef dx_dt(x):\n    return -k * x\n\nk = .5\nh = 0.001\nN0 = 100.\n\nt = np.arange(0, 10, h)\ny = np.zeros(len(t))\n\ny[0] = N0\nfor i in range(1, len(t)):\n    # Euler's method\n    y[i] = y[i-1] + dx_dt(y[i-1]) * h\n\nmax_error = abs(y-N(t)).max()\nprint(\"Max difference between the exact solution and \\nEuler's approximation with step size h=0.001:\")\nprint('{0:.15}'.format(max_error))\n\n\n# Create some point from exact solution for comparison\nte = np.linspace(0, 10, 10)\nye = N(te)\n\nplt.plot(t, y, 'b-', te, ye, 'ro')\n","tags":"lines","title":"euler.py","modified":"20210108093939650","type":"text/plain"}]