| 1 | <!doctype html> |
| 2 | <html lang="en"> |
| 3 | <head> |
| 4 | <meta charset="utf-8"> |
| 5 | <link rel="icon" href="data:,"> |
| 6 | <style> |
| 7 | body{ |
| 8 | background-color: black; |
| 9 | color: white; |
| 10 | } |
| 11 | |
| 12 | /* https://stackoverflow.com/questions/7011602/stretching-iframe-in-html5 */ |
| 13 | #wrap_all { display: none; position:fixed; width:100%; height:100%; top: 0px; left: 0px; } |
| 14 | |
| 15 | |
| 16 | iframe{ |
| 17 | position: absolute; |
| 18 | width: 100%; |
| 19 | height: 100%; |
| 20 | display: none; |
| 21 | } |
| 22 | #status{ |
| 23 | flex: 0 0 1.3em; |
| 24 | } |
| 25 | |
| 26 | #display_wrap{ |
| 27 | flex: 1 0 auto; |
| 28 | } |
| 29 | #controller{ |
| 30 | flex: 0 0 50px; |
| 31 | } |
| 32 | |
| 33 | .control-button{ |
| 34 | } |
| 35 | |
| 36 | |
| 37 | |
| 38 | .tokenlist, .fileline{ |
| 39 | border: 1px solid gray; |
| 40 | padding: 2px; |
| 41 | line-height: 1.5em; |
| 42 | } |
| 43 | |
| 44 | .fileline{ |
| 45 | background-color: #404040; |
| 46 | } |
| 47 | |
| 48 | .explicit_char_target{ |
| 49 | background-color: #FF8080; |
| 50 | } |
| 51 | .explicit_char{ |
| 52 | background-color: #606060; |
| 53 | } |
| 54 | |
| 55 | |
| 56 | .cs, .active_char{ |
| 57 | color: #FFFF00; |
| 58 | } |
| 59 | |
| 60 | #popup{ |
| 61 | display: none; |
| 62 | position: absolute; |
| 63 | border: 1px solid gray; |
| 64 | background-color: #000080ff; |
| 65 | } |
| 66 | |
| 67 | .cmd__left_brace_cmd, .cmd__right_brace_cmd, .cmd__mac_param_cmd, .frozenrelax{ |
| 68 | color: #FFAAAA; |
| 69 | } |
| 70 | .cmd__out_param_cmd{ |
| 71 | border: 1px solid #FFAAAA; |
| 72 | } |
| 73 | .out_param_expansion{ |
| 74 | border: 1px solid #FFAAAA; |
| 75 | background-color: #000080; |
| 76 | } |
| 77 | .cmd__out_param_cmd::before{ |
| 78 | content: "#"; |
| 79 | } |
| 80 | |
| 81 | .cmd__letter_cmd{ |
| 82 | color: #AAFFAA; |
| 83 | } |
| 84 | |
| 85 | .cmd__spacer_cmd{ |
| 86 | color: #606060; |
| 87 | } |
| 88 | |
| 89 | |
| 90 | input[type=button]{ |
| 91 | color: white; |
| 92 | background-color: #0000ff; |
| 93 | border: 0; |
| 94 | } |
| 95 | |
| 96 | #log{ |
| 97 | display: flex; |
| 98 | flex-direction: column-reverse; |
| 99 | flex: 0 0 30%; |
| 100 | overflow: scroll; |
| 101 | } |
| 102 | |
| 103 | /* |
| 104 | hack to make it display as ␣ but copy-paste (or search) as space |
| 105 | */ |
| 106 | .space_charcode{ |
| 107 | font-size: 0pt; |
| 108 | } |
| 109 | |
| 110 | .space_charcode::before{ |
| 111 | font-size: medium; |
| 112 | content: "␣"; |
| 113 | } |
| 114 | </style> |
| 115 | </head> |
| 116 | <body> |
| 117 | |
| 118 | <div id=output></div> |
| 119 | <div id=wrap_all> |
| 120 | <iframe id=iframe src="about:blank" frameborder=0></iframe> |
| 121 | <iframe id=iframe2 src="about:blank" frameborder=0></iframe> |
| 122 | </div> |
| 123 | <script> |
| 124 | "use strict" |
| 125 | |
| 126 | function show_html_except_space(s){ |
| 127 | return s |
| 128 | .replace(/\r|\n/g, "↵") |
| 129 | .replace(/\t/g, "⇥") |
| 130 | } |
| 131 | |
| 132 | function show_html(s){ |
| 133 | return show_html_except_space(s).replace(/ /g, "␣") |
| 134 | } |
| 135 | |
| 136 | output.innerHTML="" |
| 137 | |
| 138 | function print_tl(...tokens){ |
| 139 | const tl_div=document.createElement("div") |
| 140 | tl_div.classList.add("tokenlist") |
| 141 | for(let token of tokens){ |
| 142 | tl_div.appendChild(token) |
| 143 | if({13: true, 10: true}[token.data_charcode]){ |
| 144 | tl_div.appendChild(document.createElement("br")) |
| 145 | }else{ |
| 146 | tl_div.appendChild(document.createElement("wbr")) |
| 147 | } |
| 148 | } |
| 149 | output.appendChild(tl_div) |
| 150 | } |
| 151 | |
| 152 | function token(charcode /* int */, catcode /* single character string in hex */){ |
| 153 | const token_span=document.createElement("span") |
| 154 | const ch=String.fromCodePoint(charcode) |
| 155 | token_span.innerText=show_html_except_space(ch) |
| 156 | token_span.data_charcode=charcode |
| 157 | if(charcode==32){ // special handle space here |
| 158 | token_span.classList.add("space_charcode") |
| 159 | } |
| 160 | if(catcode==='D'){ |
| 161 | token_span.classList.add("active_char") |
| 162 | token_span.title=`active ${ch} # ${charcode}` |
| 163 | }else{ |
| 164 | const cls={ |
| 165 | 1: 'cmd__left_brace_cmd', |
| 166 | 2: 'cmd__right_brace_cmd', |
| 167 | 3: 'cmd__math_shift_cmd', |
| 168 | 4: 'cmd__tab_mark_cmd', |
| 169 | 6: 'cmd__mac_param_cmd', |
| 170 | 7: 'cmd__sup_mark_cmd', |
| 171 | 8: 'cmd__sub_mark_cmd', |
| 172 | A: 'cmd__spacer_cmd', |
| 173 | B: 'cmd__letter_cmd', |
| 174 | C: 'cmd__other_char_cmd', |
| 175 | }[catcode] |
| 176 | token_span.classList.add("token", cls) |
| 177 | token_span.title=`${cls} ${ch} # ${charcode}` |
| 178 | } |
| 179 | return token_span |
| 180 | } |
| 181 | |
| 182 | function cs(...codepoints){ |
| 183 | const token_span=document.createElement("span") |
| 184 | |
| 185 | const control_sequence_name=String.fromCodePoint(...codepoints) |
| 186 | //const meaning_str=readstr() |
| 187 | |
| 188 | /* |
| 189 | token_span.innerText='\\' + show_html(control_sequence_name) + ' ' |
| 190 | */ |
| 191 | |
| 192 | var items=control_sequence_name.split(' ') |
| 193 | items[0]="\\"+items[0] |
| 194 | items[items.length-1]+=' ' |
| 195 | for(var i=0; i<items.length; i++){ |
| 196 | if(i!=0){ // append a '␣' span that copy-paste as a space |
| 197 | var space_span=document.createElement("span") |
| 198 | space_span.innerText=' ' |
| 199 | space_span.classList.add("space_charcode") |
| 200 | token_span.appendChild(space_span) |
| 201 | } |
| 202 | |
| 203 | // append the text itself |
| 204 | if(items[i]!="") |
| 205 | token_span.appendChild(new Text(show_html_except_space(items[i]))) |
| 206 | } |
| 207 | |
| 208 | //token_span.title=`cs '${control_sequence_name}' → ${meaning_str}` |
| 209 | token_span.classList.add("cs") |
| 210 | |
| 211 | return token_span |
| 212 | } |
| 213 | |
| 214 | function csfrozenrelax(){ |
| 215 | const token_span=document.createElement("span") |
| 216 | token_span.innerText="\\relax" |
| 217 | token_span.title="frozen relax" |
| 218 | token_span.classList.add("cs", "frozenrelax") |
| 219 | return token_span |
| 220 | } |
| 221 | |
| 222 | var refresh_strategy_already_set=false |
| 223 | function set_refresh_strategy(strategy, duration){ |
| 224 | if(refresh_strategy_already_set) return |
| 225 | refresh_strategy_already_set=true |
| 226 | |
| 227 | switch(strategy){ |
| 228 | case 0: // do nothing |
| 229 | return |
| 230 | |
| 231 | case 1: // refresh the sub-iframe |
| 232 | if(window.parent===window){ |
| 233 | print_tl=function(...x) {} |
| 234 | //output.style.display="none" |
| 235 | iframe.src=location.href |
| 236 | iframe.style.display="block" |
| 237 | wrap_all.style.display="block" |
| 238 | setInterval(function(){ |
| 239 | iframe.src=iframe.src |
| 240 | }, duration) |
| 241 | } |
| 242 | return |
| 243 | |
| 244 | case 2: // refresh two sub-iframes |
| 245 | if(window.parent===window){ |
| 246 | print_tl=function(...x) {} |
| 247 | //output.style.display="none" |
| 248 | iframe.src=iframe2.src=location.href |
| 249 | iframe.style.display="block" |
| 250 | iframe2.style.display="block" |
| 251 | wrap_all.style.display="block" |
| 252 | async function sleep(ms){ |
| 253 | await new Promise(resolve=>setTimeout(resolve, ms)) |
| 254 | } |
| 255 | (async function(){ |
| 256 | while(true){ |
| 257 | await sleep(duration/2) |
| 258 | iframe.src=iframe.src |
| 259 | |
| 260 | await sleep(duration/2) |
| 261 | iframe2.style.zIndex=1 |
| 262 | iframe.style.zIndex=2 |
| 263 | |
| 264 | await sleep(duration/2) |
| 265 | iframe2.src=iframe2.src |
| 266 | |
| 267 | await sleep(duration/2) |
| 268 | iframe.style.zIndex=1 |
| 269 | iframe2.style.zIndex=2 |
| 270 | } |
| 271 | })() |
| 272 | } |
| 273 | return |
| 274 | |
| 275 | case 3: // refresh whole page |
| 276 | setTimeout(function(){ |
| 277 | location.reload() |
| 278 | }, duration) |
| 279 | return |
| 280 | |
| 281 | case 4: // request own file |
| 282 | window.addEventListener("load", async function(){ |
| 283 | async function get_code(){ |
| 284 | //let text=await (await fetch(location.href)).text() |
| 285 | let text=await new Promise(function(resolve){ |
| 286 | let request = new XMLHttpRequest(); |
| 287 | request.responseType = "text" |
| 288 | request.onload = function() { |
| 289 | resolve(request.responseText) |
| 290 | } |
| 291 | request.onerror = function() { |
| 292 | console.log("Error happened. Read documentation for more details.") |
| 293 | } |
| 294 | request.open("GET", location.href, true) |
| 295 | request.send() |
| 296 | }) |
| 297 | return text.replace(/.*?-end-template()-/s, "") |
| 298 | } |
| 299 | let text=await get_code() |
| 300 | output.innerHTML="" |
| 301 | try{ eval(text) }catch(e) {} |
| 302 | setInterval(async function(){ |
| 303 | let text2=await get_code() |
| 304 | if(text2!==text){ |
| 305 | output.innerHTML="" |
| 306 | try{ eval(text2) }catch(e) {} |
| 307 | text=text2 |
| 308 | } |
| 309 | }, duration) |
| 310 | }) |
| 311 | return |
| 312 | } |
| 313 | } |
| 314 | </script> |
| 315 | |
| 316 | <script> |
| 317 | // -end-template- |