" . "
") ("
" . "") ("View ORCID Profile" . "") (" gf " . " _g~f~_ ") (" gf." . " _g~f~_.") ("(gf)" . "(_g~f~_)") ("_gf_" . "_g~f~_") (" gF" . " _g~f~_") ("Gq" . "_G~q~_") ("Gc" . "_G~c~_") ("Gf" . "_G~f~_") ("5-HT2A" . "5-HT~2A~") ("fi" . "fi") ("" . "ff") ("ff" . "ff") ("ffi" . "ffi") ("fl" . "fl") ("" . "fi") ("AE" . "fi") ("x" . "_x_") ("y" . "_y_") (" opens in new tab." . "") ("Author links open overlay" . "") ("Get rights and content" . "") ("https://doi.org/" . "DOI: ") ("e\\. g\\." . "eg") ("1" . "1") ("2" . "2") ("3" . "3") ("4" . "4") ("1" . "1") ("2" . "2") ("3" . "3") ("4" . "4") ("*+" . "") ("+," . ",") ("++" . "") (",," . ",") (","" . "",") ("''" . "\"") ("''" . "\"") (" . " " ") ; replace THIN SPACE ("](!)" . "](!W)") ("~" . "~") ("randomis" . "randomiz") ("mendelian random" . "Mendelian random") ("behaviour" . "behavior") (" utilise" . "use") (" utilize" . "use") ("randomis" . "randomiz") (" utilising" . " using") (" utilizing" . " using") (" utilisation" . " usage") (" utilization" . " usage") ("\n* " . " * ") (" colour" . " color") ("](/docs/" . "](/doc/") ("href=\"/docs/" . "href=\"/doc/") ("href='/docs/" . "href='/doc/") ("]/doc" . "](/doc") (" n = " . " _n_ = ") ("(n = " . "(_n_ = ") ("(N=" . "(_n_ = ") ("(n=" . "(_n_ = ") ("(_n_=" . "(_n_ = ") ("|rg|" . "|rg|") ("| rg |" . "|rg|") ("| _r~g~_ |" . "|rg|") ("|ra|" . "|ra|") ("| ra |" . "|ra|") ("| _r~a~_ |" . "|ra|") ("(rtt = " . "(rtt = ") (" n = " . " _n_ = ") ("(n " . "(_n_ ") (" n " . " _n_ ") ("(n " . "(_n_ ") ("(ie, " . "(ie ") ("(ie " . "(ie ") ("(i\\.e\\.," . "(ie") ("(i\\.e\\." . "(ie") ("(ie\\." . "(ie") ("e\\.g\\., " . "eg ") (" e\\.g\\." . " eg") ("(e\\.g\\." . "(eg") ("eg\\., " . "eg ") ("(eg\\." . "(eg") ("Na\\+" . "Na+") ("K\\+" . "K+") ("Ca2+" . "Ca2+") ("+" . "+") ("+-" . "+-") ("+/-" . "+-") ("+/-" . "+-") ("et al.\n" . "et al") (" o 2" . " o2") ("t2" . "t2") ("o2" . "o2") ("TC1" . "TC1") ("chi-squared" . "kh2") ("X2(2)" . "kh2") ("F1-ATPase" . "F1-ATPase") ("a3b3" . "a3b3") (" Escherichia coli" . " Escherichia coli") (" E\\. coli" . " E. coli") (" Saccharomyces cerevisiae" . " Saccharomyces cerevisiae") (" in vivo " . " _in vivo_ ") (" ex vivo " . " _ex vivo_ ") ("two-by-two" . "2x2") (" B\\.M\\.I\\." . " BMI") (" A\\.I\\." . " AI") (" C\\.E\\.O\\." . " CEO") ("controled" . "controlled") ("one-fourth" . "1/4") ("one-half" . "1/2") ("One-fifth" . "1/5th") ("one-sixth" . "1/6th") ("three-quarters" . "3/4ths") ("two-thirds" . "2/3rds") ("2 thirds" . "2/3rds") ("and/ or" . "and/or") ("\\[\\]\\(\\!W\\)" . " ERROR ") ("( " . "(") ("" . "") ("" . "") ("" . "") ("" . "") ("]9/doc" . "](/doc") ("on X (formerly Twitter)" . "on Twitter") ("on X:" . "on Twitter:") (" X (formerly known as Twitter)" . " Twitter") ("Elon Musk's X" . "Elon Musk's Twitter") (" target=\"_blank\"" . "") ("\\.," . ". ") ("**: : " . ": ") (">: : " . ">: ") ("->>" . "-") ("-->" . "-") ) ) ) (dolist (pair blind) (replace-all (car pair) (cdr pair))) ) (let ((queries '( ; do non-regexp fixed-string query-replace queries: (" '" . " '") ("]/" . "](/") ; (" * " . ", ") (","" . "",") ("'''''" . "**_") ("'''" . "**") (" . " " ") ("''" . "\"") ("( " . "(") ("| " . "|") ("|-|" . "|-|") ; EN DASH: absolute value ranges (" )" . ")") ("?!" . "!?") ("!?" . "!?") (" ?" . "?") (" -- " . "--") (" - " . "--") (" - " . "--") (" -> " . "-") ("~>" . "-") (" percent " . "% ") (" per cent " . "% ") ("95 %CI" . "95% CI") ("(95% CI, " . "(95% CI: ") ("95 % confidence interval" . "95% confidence interval") (" , " . ", ") ("http://reddit.com" . "https://www.reddit.com") ("https://reddit.com" . "https://www.reddit.com") ("http://i.reddit.com" . "https://www.reddit.com") ("https://mobile.x.com" . "https://x.com") (" d=" . " _d_ = ") ; italicize p-values & sample sizes: (" d = " . " _d_ = ") ("(d = " . "(_d_ = ") ("(d >= " . "(_d_ >= ") ("(d < " . "(_d_ < ") ("Cohen's d" . "Cohen's _d_") ("P=" . "_p_ = ") ("pone-tailed" . "pone-tailed") ("ptrend" . "ptrend") ("pmeta" . "pmeta") ("pinteraction" . "pinteraction") ("p0" . "p0") ("pgc" . "pgc") ("(N" . "(_n_ ") ("(n, " . "(_n_, ") (" N)" . " _n_)") ("[n = " . "[_n_ = ") ("[N=" . "[_n_ = ") ("[n=" . "[_n_ = ") ("[N" . "[_n_ ") (" n=" . " _n_ = ") (" N = " . " _n_ = ") (" N=" . " _n_ = ") (" n =" . " _n_ = ") (" n " . " _n_ ") (" _n_=" . " _n_ = ") ("n = " . "_n_ = ") ("N = " . "_n_ = ") (" n<=" . " _n_ <= ") (" n>=" . " _n_ >= ") ("lN" . "ln") (" O(" . " O(") ("( r =" . "(_r_ =") ("(r)" . "(_r_)") ("(r >=" . "(_r_ >=") ("<= r <=" . "<= _r_ <=") ("<= r " . "<= _r_ ") (" r <=" . " _r_ <=") (" r values" . " _r_ values") ("(rs =" . "(rs =") (" rs =" . " rs =") ("rmeta =" . "rmeta =") ("rUKB =" . "rUKB =") (" r " . " _r_ ") ("Mr = " . "_M_~r~ = ") ("zMR " . "_z_~MR~ ") ("z score" . "_z_ score") ("z-score" . "_z_-score") (" z-" . " _z_-") ("Mage=" . "M~age~ = ") ("Mage " . "M~age~ ") ("Mage " . "M~age~ ") ("tmax " . "t~max~ ") ("Cmax" . "C~max~") ("AUClast" . "AUC~last~") ("AUC" . "AUC~~") ("AUC0-t" . "AUC~0-t~") ("SDage=" . "SD~age~ = ") ("SDage " . "SD~age~ ") ("mean=" . "mean = ") ("OR=" . "OR = ") ("AOR=" . "AOR = ") ("RR=" . "RR = ") ("r =" . "_r_ = ") ("r=" . "_r_ = ") ("r = " . "_r_ = ") ("r' =" . "_r'_ = ") ("(r range = " . "(_r_ range = ") (" r's " . " _r_'s ") ("r " . "_r_ ") (" rs " . " rs ") (" r-value" . " r-value") (" p = " . " _p_ = ") (" p=" . " _p_ = ") (" p =" . " _p_ = ") ("(p = " . "(_p_ = ") ("[p = " . "[_p_ = ") ("(P=" . "(_p_ = ") ("p-value" . "_p_-value") ("p value" . "_p_-value") ("p-curve" . "_p_-curve") ("Padj" . "_p_adj") (" po " . " orally ") ("(t<" . "(_t_ < ") ("(t>" . "(_t_ > " ) (" t-statistic" . " _t_-statistic" ) ("HR=" . "HR = ") ("rP=" . "_r~p~_ = ") ("rP = " . "_r~p~_ = ") ("rg=" . "_r~g~_ = ") ("rg = " . "_r~g~_ = ") ("(rg)" . "(_r~g~_)") ("(rg " . "(_r~g~_ ") (" rg " . " _r~g~_ ") ("ra = " . "_r~a~_ = ") ("(ra)" . "(_r~a~_)") ("(ra " . "(_r~a~_ ") (" ra " . " _r~a~_ ") ("QM[" . "_Q_~M~[") ("QM(" . "_Q_~M~(") ("= ." . "= 0.") ("< ." . "< 0.") (" > ." . "> 0.") ("r =" . "_r_ =") ("SE=" . "SE = ") ("=" . " = ") (">" . " > ") ("<" . " < ") ("<" . " < ") (">" . " > ") (" >> " . " ") (" << " . " ") ("_<" . "_ < ") ("_>" . "_ > ") ("=." . " = 0.") ("(.0" . "(0.0") (" < .0" . " < 0.0") ("=1 " . " = 1 ") ("=2 " . " = 2 " ) ("(p < 0." . "(_p_ < 0.") (" p value" . " _p_-value") (" p-hack" . " _p_-hack") (" p " . " _p_ ") (" <0." . " < 0.") ("<=" . "<=") (">=" . ">=") ("( N " . "(_n_ ") ("( _n_" . "(_n_ ") ("n-gram" . "n-gram") ("k-mean" . "k-mean") ("partial I*2" . "partial e2") ("e2p" . "ep2") ("s9 " . "s' ") ; workaround MedRxiv/BioRxiv consistent malformation of "s'" as "s9" (somehow); can't auto-replace due to 'CRISPR-Cas9' etc (" -." . " -0.") ("50/50" . "50:50") (" 1/4" . "1/4") ("C3O2" . "C~3~O~2~") ("CO2" . "CO~2~") (" CO2" . " CO~2~") ("CO2." . "CO~2~") ("O2" . "O~2~") ("b42" . "b~42~") ("bA" . "b~A~") ("bC" . "b~C~") ("bE" . "b~E~") ("CH4" . "CH~4~") ("PH3" . "PH~3~") ("PM2.5" . "PM2.5") ("mg/m3" . "mgm3") ("H2" . "H~2~") ("H2O" . "H~2~O") ("cm-2" . "cm^-2^") ("cm-2" . "cm^-2^") ("cm3" . "cm^3^") (" m3" . " m^3^") ("kg/m2" . "kgm^2^") (" m2" . "m^2^") (" m^2 " . "m^2^ ") ("x1-1xmin" . " x 1-1 x min") ("t1/2" . "t1/2") (" m/s" . " ms") (" km/s" . " kms") ("km2" . "km^2^") ("um3" . "um^3^") (" ug" . " mg") ("k2" . "k^2^") ("min-1" . "min-1") ("min-1" . "min-1") (" s-1" . " s^-1^") (" s-1" . " s^-1^") ("ml-1" . "ml-1") ("^-1 " . "^-1^ ") (" d-1" . " d-1") ("dl-1" . "dl-1") ("kb-1" . "kb-1") (" g-related" . " _g_-related") ("g+ " . "_g_^+^ ") ("g-factor" . "_g_-factor") ("g-load" . "_g_-load") ("(g)" . "(_g_)") (" g." . " _g_.") (" g," . " _g_,") (" g:" . " _g_:") (" g " . " _g_ ") ("(g=" . "(_g_ = ") ("mg L-1" . "mg _L_^-1^") ("tau181" . "tau~181~") ("vitamin D3" . "vitamin D~3~") ("vitamin D4" . "vitamin D~4~") (" \" . " . " \"") (" \\times " . " \cdot ") ("''" . "\"") ("``" . "\"") ("$\alpha$" . "a") ("$\beta$" . "b") ("$\sigma$" . "s") ("Neff=" . "_N_~eff~ = ") ("Neff" . "_N_~eff~") ("Ntotal" . "_N_~total~") (" Ne " . " Ne ") ("$N_e$" . "_N_~_e_~") ("ntotal", "ntotal") ("n~total~", "ntotal") ("$\frac{n}{2}$" . "_n_2") ("$\frac{N}{2}$" . "_n_2") ("b = " . "b = ") ("b = -" . "b = -") ("_b_ = " . "b = ") ("_b_ = -" . "b = -") (" a2" . " _a_^2^") (" c2" . " _c_^2^") (" e2" . " _e_^2^") ("(a2" . "(_a_^2^") ("(c2" . "(_c_^2^") ("(e2" . "(_e_^2^") ("h2SNP" . "h2SNP") ("h2snp" . "h2SNP") ("h2 " . "_h_^2^ ") (" h2" . " _h_^2^") ("(h2=" . "(_h_^2^ = ") ("(h2 = " . "(_h_^2^ = ") ("h2 = " . "_h_^2^ = ") ("c 2" . "_c_^2^") ("h^2SNP" . "h2SNP") ("_h_^2^ = " . "_h_^2^ = ") ("Fst" . "F~st~") ("rMZ" . "_r_~MZ~") ("rDZ" . "_r_~DZ~") ("R22" . "_R_22") (" Wm-1" . " Wm-1") (" K-1" . " K-1") (" kg-1" . " kg-1") ("mg-1" . "mg-1") ("mg-1" . "mg-1") ("l-1" . "l-1") ("m s--1" . "m s-1") ("cm--3" . "cm-3") (" cm2" . " cm2") ("mL/cm2" . "mLcm2") ("mg/week" . "mgweek") ("m*h-1" . "mxh-") (" " . "") (" " . "") ("60Co" . "^60^Co") (" I2" . " _I_^2^") ("<=p<=" . " <= _p_ <= ") ("BF10" . "BF10") ("BF10" . "BF10") ("BF01" . "BF10") ("L2" . "l2") ("L1" . "l1") (": " . ": ") ("(i)" . "(1)") ("(ii)" . "(2)") ("(iii)" . "(3)") ("(iv)" . "(4)") ("(v)" . "(5)") ("(vi)" . "(6)") ("(vii)" . "(7)") ("(viii)" . "(8)") ("(ix)" . "(9)") ("(x)" . "(10)") ("(a)" . "(1)") ("(b)" . "(2)") ("(c)" . "(3)") ("(d)" . "(4)") ("(e)" . "(5)") ("(f)" . "(6)") ("(g)" . "(7)") ("(h)" . "(8)") ("(i)" . "(9)") ("(j)" . "(10)") (" i)" . " (1)") (" ii)" . " (2)") (" iii)" . " (3)") (" iv)" . " (4)") (" v)" . " (5)") (" vi)" . " (6)") (" vii)" . " (7)") (" viii)" . " (8)") (" ix)" . " (9)") (" x)" . " (10)") ("DALL-E" . "DALL*E") ("DALL-e" . "DALL*E") ("NOVA1" . "_NOVA1_") (" X " . " Twitter ") (" X." . " Twitter.") (" X," . " Twitter.") (" X;" . " Twitter.") ("X, formerly known as Twitter," . "Twitter") ("x-axis" . "_x_-axis") ("x axis" . "_x_-axis") ("z axis" . "_z_-axis") ("y-axis" . "_y_-axis") (" y-value" . " _y_-value") (" x-value" . " _x_-value") (" z-value" . " _z_-value") ("z-axis" . "_z_-axis") ("y axis" . "_y_-axis") ("x-axes" . "_x_-axes") ("x axes" . "_x_-axes") ("z-axes" . "_z_-axes") ("z axes" . "_z_-axes") ("y-axes" . "_y_-axes") ("y axes" . "_y_-axes") (" x " . " _x_ ") (" x:" . " _x_:") (" y " . " _y_ ") (" y:" . " _y_:") (" z " . " _z_ ") (" k " . " _k_ ") (" k=" . " _k_ =") (" n " . " _n_ ") ("(n2)" . "(_n_^2^)") ("(n3)" . "(_n_^3^)") ("n-" . "_n_ - ") ("n-back" . "_n_-back") (" n-body" . " _n_-body") ("log 2" . "log2") ("fuck" . "f--k") ("damn" . "d--n") ("shit" . "s--t") ("95%CI" . "95% CI") ("allowlist" . "whitelist") ("denylist" . "blacklist") ("PGI" . "PGS") (" " . "") ; can't auto-replace because of instances like isotopic elements with *prefixed* superscripts, eg ' 60Co' ("BCE" . "BC") ("CE" . "AD") (", opens new tab " . "") ; Reuters tooltip/alt for links, which copy-pastes, annoyingly ; replace all word-numbers with actual numbers: (" one-hundred" . " 100") (" one hundred" . " 100") (" ninety nine" . " 99") (" ninety-nine" . " 99") (" ninety eight" . " 98") (" ninety-eight" . " 98") (" ninety seven" . " 97") (" ninety-seven" . " 97") (" ninety six" . " 96") (" ninety-six" . " 96") (" ninety five" . " 95") (" ninety-five" . " 95") (" ninety four" . " 94") (" ninety-four" . " 94") (" ninety three" . " 93") (" ninety-three" . " 93") (" ninety two" . " 92") (" ninety-two" . " 92") (" ninety one" . " 91") (" ninety-one" . " 91") (" ninety" . " 90") (" eighty nine" . " 89") (" eighty-nine" . " 89") (" eighty eight" . " 88") (" eighty-eight" . " 88") (" eighty seven" . " 87") (" eighty-seven" . " 87") (" eighty six" . " 86") (" eighty-six" . " 86") (" eighty five" . " 85") (" eighty-five" . " 85") (" eighty four" . " 84") (" eighty-four" . " 84") (" eighty three" . " 83") (" eighty-three" . " 83") (" eighty two" . " 82") (" eighty-two" . " 82") (" eighty one" . " 81") (" eighty-one" . " 81") (" eighty" . " 80") (" seventy nine" . " 79") (" seventy-nine" . " 79") (" seventy eight" . " 78") (" seventy-eight" . " 78") (" seventy seven" . " 77") (" seventy-seven" . " 77") (" seventy six" . " 76") (" seventy-six" . " 76") (" seventy five" . " 75") (" seventy-five" . " 75") (" seventy four" . " 74") (" seventy-four" . " 74") (" seventy three" . " 73") (" seventy-three" . " 73") (" seventy two" . " 72") (" seventy-two" . " 72") (" seventy one" . " 71") (" seventy-one" . " 71") (" seventy" . " 70") ("sixties" . "60s") (" sixty nine" . " 69") (" sixty-nine" . " 69") (" sixty eight" . " 68") (" sixty-eight" . " 68") (" sixty seven" . " 67") (" sixty-seven" . " 67") (" sixty six" . " 66") (" sixty-six" . " 66") (" sixty five" . " 65") (" sixty-five" . " 65") (" sixty four" . " 64") (" sixty-four" . " 64") (" sixty three" . " 63") (" sixty-three" . " 63") (" sixty two" . " 62") (" sixty-two" . " 62") (" sixty one" . " 61") (" sixty-one" . " 61") (" sixty" . " 60") (" fifty nine" . " 59") (" fifty-nine" . " 59") (" fifty eight" . " 58") (" fifty-eight" . " 58") (" fifty seven" . " 57") (" fifty-seven" . " 57") (" fifty six" . " 56") (" fifty-six" . " 56") (" fifty five" . " 55") (" fifty-five" . " 55") (" fifty four" . " 54") (" fifty-four" . " 54") (" fifty three" . " 53") (" fifty-three" . " 53") (" fifty two" . " 52") (" fifty-two" . " 52") (" fifty one" . " 51") (" fifty-one" . " 51") (" fifty" . " 50") (" forty nine" . " 49") (" forty-nine" . " 49") (" forty eight" . " 48") (" forty-eight" . " 48") (" forty seven" . " 47") (" forty-seven" . " 47") (" forty six" . " 46") (" forty-six" . " 46") (" forty five" . " 45") (" forty-five" . " 45") (" forty four" . " 44") (" forty-four" . " 44") (" forty three" . " 43") (" forty-three" . " 43") (" forty two" . " 42") (" forty-two" . " 42") (" forty one" . " 41") (" forty-one" . " 41") (" forty" . " 40") (" thirty nine" . " 39") (" thirty-nine" . " 39") (" thirty eight" . " 38") (" thirty-eight" . " 38") (" thirty seven" . " 37") (" thirty-seven" . " 37") (" thirty six" . " 36") (" thirty-six" . " 36") (" thirty five" . " 35") (" thirty-five" . " 35") (" thirty four" . " 34") (" thirty-four" . " 34") (" thirty three" . " 33") (" thirty-three" . " 33") (" thirty two" . " 32") (" thirty-two" . " 32") (" thirty one" . " 31") (" thirty-one" . " 31") (" thirty" . " 30") (" twenty nine" . " 29") (" twenty-nine" . " 29") (" twenty eight" . " 28") (" twenty-eight" . " 28") (" twenty seven" . " 27") (" twenty-seven" . " 27") (" twenty six" . " 26") (" twenty-six" . " 26") (" twenty five" . " 25") (" twenty-five" . " 25") (" twenty four" . " 24") (" twenty-four" . " 24") (" twenty three" . " 23") (" twenty-three" . " 23") (" twenty two" . " 22") (" twenty-two" . " 22") (" twenty one" . " 21") (" twenty-one" . " 21") ("twenty-first century" . "21st century") (" twenty" . " 20") (" twentieth" . " 20th") (" nineteen" . " 19") ("nineteenth" . " 19th") (" eighteen" . " 18") (" seventeen" . " 17") (" sixteen" . " 16") (" fifteen" . " 15") (" fourteen" . " 14") (" thirteen" . " 13") (" twelve" . " 12") (" eleven" . " 11") (" ten " . " 10 ") (" nine" . " 9") (" eight" . " 8") (" seven" . " 7") (" six" . " 6") (" five" . " 5") (" four" . " 4") (" three" . " 3") ("Ten " . "10 ") ("Nine " . " 9") ("Eight " . "8 ") ("Seven " . "7 ") ("Six " . "6 ") ("Five " . "5 ") ("Four " . "4 ") ("Three " . "3 ") ; look for possible screwed-up exponentials (" 1015" . " 10^15^") (" 1014" . " 10^14^") (" 1013" . " 10^13^") (" 1012" . " 10^12^") (" 1011" . " 10^11^") (" 1010" . " 10^10^") (" 109" . " 10^9^") (" 108" . " 10^8^") (" 107" . " 10^7^") (" 106" . " 10^6^") (" 105" . " 10^5^") (" 104" . " 10^4^") (" 103" . " 10^3^") (" 102" . " 10^2^") ) ) ) (dolist (pair queries) (query-replace (car pair) (cdr pair) nil begin end)) ) (let ((regexps '( ("!!+" . "!") ("\\([[:alnum:]]\\) \\([[:graph:]]\\)" . "\\1 \\2") ; remove subtle whitespace problems: double space ("\\([a-z]+\\),\\([a-z]+\\)" . "\\1, \\2") ; run-together comma phrases often appear in PDF OCR like 'foo,bar'; outside chemical names, this is highly unusual. ("\\([0-9]+\\)[ ]\\([0-9]+\\)" . "\\1,\\2") ; '50 000' or '50 000' - '50,000' ("\\([[:punct:]]\\)p<" . "\\1_p_ <") (" Ne\\\([[:punct:]]\\)" . " Ne\\1") ("\\\([[:punct:]]\\)Ne " . "\\1Ne ") ("\\([a-zA-Z]+\\)2\\([a-zA-Z]+\\)" . "\\12\\2") ; numbers, superscripts: ("\\([023456789]\\)th" . "\\1^th^") ("\\([1]\\)st" . "\\1^st^") ("\\([3]\\)rd" . "\\1^rd^") ; ("\\(four\\|fif\\|six\\|seven\\|eigh\\|nin\\|ten\\)th" . "\\1^th^") ; ("\\(four\\|fif\\|six\\|seven\\|eigh\\|nin\\|ten\\)th" . "\\1^th^") ; numbers, ranges or changes: ; NOTE: we deliberately omit EN DASH-ification of ranges involving negative numbers. For example, '-0.3 to -3.7' ; would look confusing if written '-0.3--3.7'. It's correct & unambiguous because it uses MINUS SIGN & EN DASH ; appropriately, but the glyphs are way too similar-looking. (Sorry, I didn't design English punctuation.) ; And this is also true if any of the numbers have minus signs (eg. '-0.3-3.7' or '0.3--3.7' would be no better). ("between \\([0-9.]+\\) and \\([0-9.]+\\)" . "\\1-\\2") (" one to \\([0-9.]+\\)" . " 1-\\1") ("from \\([0-9.]+\\) to \\([0-9.]+\\)" . "\\1-\\2") ("\\([0-9\\.]+\\) to \\([0-9\\.]+\\)" . "\\1-\\2") ("\\([0-9\\.]+\\) through \\([0-9\\.]+\\)" . "\\1-\\2") ("from \\([0-9%.]+\\|one\\|two\\|three\\) to \\([0-9.]+\\)" . "\\1 - \\2") ("\\([a-z]+\\)- and \\([a-z]+-[a-z]+\\)" . "\\1 & \\2") ("\\([0-9.]+\\|one\\|two\\|three\\) to \\([0-9.]+\\)" . "\\1 - \\2") ("between \\([0-9.]+\\) and \\([0-9.]+\\)" . "\\1-\\2") ; "range between 2 and 10" - "range 2-10" (" \\([0-9.]+\\) or \\([0-9.]+\\) " . " \\1-\\2 ") ("\\([0-9.]+\\)- to \\([0-9.]+\\)-" . "\\1-\\2-") ; "18- to 20-year-olds" - "18--20-year-olds" ("95% CI = \\([0-9]\\.[0-9]+\\), \\([0-9]\\.[0-9]+\\)" . "95% CI = \\1-\\2") ("CI:\\([0-9]\\)" . "CI: \\1") ; "95% CI:0.01-0.99" (" ~ \\([0-9]+\\)" . " ~\\1") ; "a period of ~ 20 min" ("\\([^-]\\)->" . "\\1-") ; avoid closing HTML comment syntax false positives ) )) (dolist (pair regexps) (query-replace-regexp (car pair) (cdr pair) nil begin end)) ) (replace-regexp-auto "\\([0-9]\\) \\([0-9][0-9][0-9]\\)" "\\1,\\2" nil begin end) ; primarily for JAMA-formatted abstracts where they use a space separator instead of a comma: eg. "18 386" ; format abstract sub-headings with bold if we are writing an abstract and not a Markdown file: (unless (buffer-file-name) (query-replace " -\n " "" nil begin end) (query-replace " -\n" "" nil begin end) (query-replace "-\n " "" nil begin end) (query-replace "-\n" "" nil begin end) (query-replace "- \n" "" nil begin end) (query-replace "-\n" "-" nil begin end) (query-replace " -- " "---" nil begin end) (query-replace " --- " "---" nil begin end) (query-replace "--- " "---" nil begin end) (query-replace " ---" "---" nil begin end) (query-replace "----" "---" nil begin end) (query-replace " -\"" "---\"" nil begin end) (query-replace "\"- " "\"---" nil begin end) (query-replace "\nQuestion " "\n**Question**: " nil begin end) (query-replace "Question\n" "**Question**: " nil begin end) (query-replace "Question:" "**Question**: " nil begin end) (replace-all "\n\nPurpose" "\n\n**Background**:") (replace-all "\nFindings " "\n**Findings**: ") (replace-all "\nRecent Findings " "\n**Findings**: ") (replace-all "\nMeaning " "\n**Meaning**: ") (replace-all "\nMeaning\n" "\n**Meaning**: ") (replace-all "\nImportance " "\n**Importance**: ") (replace-all "\nImportance\n" "\n**Importance**: ") (replace-all "^Importance " "**Importance**: ") (replace-all "\nObjective and Method: " "\n**Objective & Method**: ") (replace-all "\nObjective " "\n**Objective**: ") (replace-all "\nDesign, Setting, and Participants " "\n**Design, Setting, & Participants**: ") (replace-all "\nDesign, Setting, and Participants\n" "\n**Design, Setting, & Participants**: ") (replace-all "\nSearch methods\n\n" "\n\nSearch Method: ") (replace-all " (Methods)" " (Method)") (replace-all "\nSelection criteria\n\n" "\n\nSelection Criteria: ") (replace-all "\nInterventions " "\n**Intervention**: ") (replace-all "\nInterventions\n" "\n**Intervention**: ") (replace-all "\nIntervention " "\n**Intervention**: ") (replace-all "\nMain Outcomes and Measures " "\n**Main Outcomes & Measures**: ") (replace-all "\nMain Outcomes and Measures\n" "\n**Main Outcomes & Measures**: ") (replace-all "Measurement and Results:" "**Measurement & Results**:") (replace-all "\nResults and conclusion " "\n**Result & Conclusion**: ") (replace-all "\nResults " "\n**Results**: ") (replace-all "\nConclusions and Relevance " "\n**Conclusion & Relevance**: ") (replace-all "\nTrial Registration " "\n**Trial Registration**: ") (replace-all "\nTrial Registration\n" "\n**Trial Registration**: ") (replace-all "Background\n" "\n**Background**: ") (replace-all "\nBackground " "**Background**: ") (replace-all "Introduction: " "\n**Introduction**: ") (replace-all "\nIntroduction. " "\n**Introduction**: ") (replace-all "\nAims\n" "\n**Aims**: ") (replace-all "\nStudy Design\n" "\n**Design**: ") (replace-all "\nDesign\n" "\n**Design**: ") (replace-all "\nSetting\n" "\n**Setting**: ") (replace-all "\nParticipants\n" "\n**Participants**: ") (replace-all "\nMeasurements\n" "\n**Measurements**: ") (replace-all "\nMaterials and methods\n" "\n\n**Method & Materials**: " ) (replace-all "\nMethods and materials\n" "\n\n**Method & Materials**: " ) (replace-all "Methods\n" "\n**Method**: ") (replace-all "\nMethods " "\n**Method**: ") (replace-all "\nMethod. " "\n**Method**: ") (replace-all "Highlights\n" "\n**Highlights**:\n\n") (replace-all "Interpretation\n" "\n**Interpretation**: ") (replace-all "Funding\n" "\n**Funding**: ") (replace-all "Highlights:" "**Highlights**: ") (replace-all "Background\\:" "**Background**: ") (replace-all "Background\\. " "**Background**: ") (replace-all "Abstract:" "**Abstract**: ") (replace-all "Context:" "**Context**: ") (replace-all "Purpose:" "**Background**: ") (replace-all "Rationale: " "**Background**: ") (replace-all "Rationale\n" "**Background**: ") (replace-all "Rationale: " "**Background**: ") (replace-all "Rationale\n\n" "**Background**: ") (replace-all "Study Objectives\n" "**Objectives**: ") (replace-all "Study Objectives:\n" "**Objectives**: ") (replace-all "Objective:" "**Objective**: ") (replace-all "Objectives:" "**Objectives**: ") (replace-all "Objectives\n" "\n**Objectives**: ") (replace-all "Aims\n\n" "\n**Aims**: ") (query-replace "Description:" "**Description**: " nil begin end) (replace-all "Design:" "**Design**: ") (replace-all "Design\n\n" "\n**Design**: ") (replace-all "Study Design and Setting\n" "**Study Design & Setting**: ") (replace-all "Subjects:" "**Subjects**: ") (replace-all "Methods:" "**Method**: ") (replace-all "Methods\\. " "**Method**: ") (replace-all "\nMethods and findings\n\n" "\n\n**Method & Findings**: ") (replace-all "\n\nDesign and methods" "\n\n**Design & Method**: ") (replace-all "Method:" "**Method**:") (replace-all "Design, Setting, and Participants:" "**Design, Setting, & Participants**: ") (replace-all "Participants and Setting:" "**Participants & Setting**: ") (replace-all "Setting:" "**Setting**: ") (replace-all "Setting\n\n" "\n**Setting**: ") (replace-all "Participants:" "**Participants**: ") (replace-all "Participants\n\n" "\n**Participants**: ") (replace-all "Meaning:" "**Meaning**: ") (replace-all "Intervention:" "**Intervention**: ") (replace-all "\nInterventions:" "\n**Intervention**: ") (replace-all "Data Sources:" "**Data Sources**: ") (replace-all "Data sources: " "**Data Sources**: ") (replace-all "Data sources\n" "**Data Sources**: ") (replace-all "Exposures:" "**Exposures**: ") (replace-all "\nExposures " "\n**Exposures**: ") (replace-all "Main Outcome Measures:" "**Main Outcome Measures**: ") (replace-all "Main outcome measures:\n" "**Main Outcome Measures**: ") (replace-all "Main outcome measure:\ " "**Main Outcome Measures**: ") (replace-all "Main outcome measures\n" "**Main Outcome Measures**: ") (replace-all "\nMain outcome measures " "\n**Main Outcome Measures**: ") (replace-all "Measurements:" "**Measurements**: ") (replace-all "Measurements\n\n" "\n**Measurements**: ") (replace-all "Main Outcome Measures:" "**Outcome Measures**: ") (replace-all "Main Outcome Measures\n" "**Outcome Measures**: ") (replace-all "Outcome measures:" "**Outcome Measures**: ") (replace-all "Outcomes:" "\n**Outcomes**: ") (replace-all "Outcomes\n\n" "\n**Outcomes**: ") (replace-all "\n\nMethods and Results\n" "\n\n**Method & Results**: ") (replace-all "Results:" "**Results**: ") (replace-all "Results\\. " "**Results**: ") (replace-all "\nResult:" "\n**Results**: ") (replace-all "\nResult\\. " "\n**Results**: ") (replace-all "Measurements and Results\n" "\n**Measurements & Results**: ") (replace-all "Results\n" "\n**Results**: ") (replace-all "Aims:" "**Aims**: ") (replace-all "Aim:\n" "**Aims**: ") (replace-all "Aim\n\n" "\n\n**Aim**: ") (replace-all "Methodology/Principal Findings\n\n" "\n**Methodology/Principal Results**: ") (replace-all "Methodology\n\n" "\n**Methodology**: ") (replace-all "Principal Findings\n\n" "\n**Principal Results**: ") (replace-all "Methods and Findings\n\n" "\n**Method & Results**: ") (replace-all "Findings\n\n" "\n**Results**: ") (replace-all "Findings\n" "\n**Results**: ") (replace-all "\nScope of review\n\n" "\n\n**Scope of Review**: ") (replace-all "\n\nReview methods " "\n\n**Review Method**: ") (replace-all "\nMajor conclusions\n\n" "\n\n**Conclusion**: ") (replace-all "\nFindings: " "\n**Results**: ") (replace-all "\nFinding: " "\n**Results**: ") (replace-all "\nFinding " "\n**Results**: ") (replace-all "\nQuestion " "\n**Question**: ") (replace-all "^Question " "**Question**: ") (replace-all "Significance:" "**Significance**: ") (replace-all "Conclusions\n\n" "\n**Conclusion**: ") (replace-all "Conclusions\n" "\n**Conclusion**: ") (replace-all "Conclusion:" "**Conclusion**: ") (replace-all "Conclusions\\. " "**Conclusion**: ") (replace-all "Conclusions:" "**Conclusion**: ") (replace-all "Conclusions and Relevance:" "**Conclusion & Relevance**: ") (replace-all "Conclusion\n" "\n**Conclusion**: ") (replace-all "\nConclusions " "\n**Conclusion**: ") (replace-all "\n\nConclusion " "\n\n**Conclusion**: ") (replace-all "Materials and Method\n" "\n**Materials & Method**: ") (replace-all "Method\n" "\n**Method**: ") (replace-all "Objective\n" "**Objective**: ") (replace-all "^Objective " "**Objective**: ") (replace-all "OBJECTIVE " "**Objective**: ") (replace-all "OBJECTIVE\n\n" "\n**Objective**: ") (replace-all "OBJECTIVE: " "\n**Objective**: ") (replace-all "\nObjectives " "\n**Objectives**: ") (replace-all "INTRODUCTION\n\n" "\n**Background**: ") (replace-all "\nContext " "\n**Background**: ") (replace-all "\nBackground and objective " "\n**Background**: ") (replace-all "INTRODUCTION\n" "**Background**: ") (replace-all "INTRODUCTION: " "**Background**: ") (replace-all "Introduction\n\n" "\n**Background**: ") (query-replace-regexp "^Introduction\n" "\n**Background**: " nil begin end) (query-replace-regexp "^INTRODUCTION " "\n**Background**: " nil begin end) (replace-all "RATIONALE\n\n" "\n**Rationale**: ") (replace-all "RATIONALE\n" "**Rationale**: ") (query-replace-regexp "^RATIONALE " "\n**Rationale**: " nil begin end) (replace-all "RESULTS\n\n" "\n**Results**: ") (replace-all "\nRESULTS: " "\n**Results**: ") (query-replace-regexp "^RESULTS " "\n**Results**: " nil begin end) (replace-all "Discussion\n\n" "\n**Discussion**: ") (replace-all "\n\nDiscussion\n\n" "\n\n**Discussion**: ") (replace-all "\n\nDiscussion" "\n\n**Discussion**: ") (replace-all "\n\nDiscussion: " "\n\n**Discussion**: ") (replace-all "CONCLUSION\n\n" "\n**Conclusion**: ") (replace-all "CONCLUSION\n" "\n**Conclusion**: ") (query-replace-regexp "^CONCLUSION " "\n**Conclusion**: " nil begin end) (query-replace "BACKGROUND" "**Background**: " nil begin end) (replace-all "Background and Aims\n" "**Background & Aims**: ") (replace-all "\n\nMETHODS\n" "\n\n**Method**: ") (replace-all "METHODS: " "**Method**: ") (replace-all "\nMETHODS " "\n**Method**: ") (replace-all "\n\nRESULTS" "\n\n**Results**: ") (replace-all "\nMain results\n\n" "\n**Results**: ") (replace-all "\n\nCONCLUSIONS" "\n\n**Conclusion**: ") (replace-all "CONCLUSIONS\n\n" "\n**Conclusion**: ") (replace-all "Conclusions/Significance\n\n" "\n**Conclusion**: ") (replace-all "\nAuthors' conclusions\n\n" "\n\n**Conclusion**: ") (replace-all "\nPractice implications" "\n**Practice Implications**: ") (replace-all "Trial Registration:" "**Trial Registration**: ") (replace-all "Trial registration:" "**Trial Registration**: ") (replace-all "Trial Registration number:" "**Trial Registration Number**: ") (replace-all "Trial Registration " "**Trial Registration**: ") (replace-all "Clinical Trial Registration:\n" "**Clinical Trial Registration**: ") (replace-all "Clinical trial registration\n" "**Clinical Trial Registration**: ") (replace-all "Clinical Translation\n\n" "\n**Clinical Translation**: ") (replace-all "\nSystematic review registration " "\n**Systematic Review Registration**: " ) (replace-all "eLife digest\n\n" "\n**eLife digest**: ") (replace-all "\nKEYWORDS:" "[**Keywords**:") (replace-all "\nKEY WORDS:" "[**Keywords**:") (replace-all "\nkey words" "[**Keywords**:") (replace-all "\nkey Words" "[**Keywords**:") (replace-all "\\[Keywords:" "[**Keywords**:") (replace-all "\\[Keyword:" "[**Keywords**:") (replace-all "Key words::" "[**Keywords**:") (replace-all "Key Messages\n" "**Key Messages**:") (replace-all "\nAuthor summary\n\n" "\n\n**Author Summary**: ") (replace-all "\nAuthor Summary\n\n" "\n\n**Author Summary**: ") (replace-all "Purpose\n\n" "\n**Background**: ") (replace-all "Purpose\n" "**Background**: ") (replace-all "Purpose of Review\n" "**Background**: ") (replace-all "Design/methodology/approach\n\n" "\n**Method**: ") (replace-all "RESEARCH DESIGN AND METHODS " "**Method**: ") (replace-all "RESEARCH DESIGN AND METHODS\n\n" "\n**Method**: ") (replace-all "METHOD: " "**Method**: ") (replace-all "\nDesign " "\n**Design**: ") (replace-all "Research limitations/implications\n\n" "\n**Research Limitations/Implications**: ") (replace-all "Strengths and Limitations\n\n" "\n**Strengths & Limitations**: ") (replace-all "\nLimitations\n" "\n\n**Limitations**: ") (replace-all "\nLimitations.\n" "\n**Limitations**: ") (replace-all "\nData Sources\n" "\n**Data Sources**: ") (replace-all "\nData Sources " "\n**Data Sources**: ") (replace-all "\nData sources " "\n**Data Sources**: ") (replace-all "\nStudy Selection\n" "\n**Study Selection**: ") (replace-all "\nStudy Selection " "\n**Study Selection**: ") (replace-all "\nStudy selection: " "\n**Study Selection**: ") (replace-all "\nData Extraction\n" "\n**Data Extraction**: ") (replace-all "\nData extraction: " "\n**Data Extraction**: ") (replace-all "\nData extraction and synthesis " "\n**Data Extraction & Synthesis**: ") (replace-all "\nData Extraction and Synthesis " "\n**Data Extraction & Synthesis**: ") (replace-all "\nData Synthesis\n" "\n**Data Synthesis**: ") (replace-all "\nData synthesis: " "\n**Data Synthesis**: ") (replace-all "\nData Synthesis " "\n**Data Synthesis**: ") (replace-all "\nData collection and analysis\n\n" "Data & Analysis: ") (replace-all "\nEligibility criteria for selecting studies " "\n**Eligibility Criteria For Selecting Studies**: ") (replace-all "Practical implications\n\n" "\n**Practical Implications**: ") (replace-all "Social implications\n\n" "\n**Social Implications**: ") (replace-all "Educational Impact and Implications Statement:" "**Educational Impact & Implications Statement**:") (replace-all "Originality/value\n\n" "\n**Originality/Value**: ") (replace-all "\nKeywords\n" "[**Keywords**: ") (replace-all "\nKeywords: " "[**Keywords**: ") (replace-all "\nKey Words\n" "\n[**Keywords**: ") (replace-all "\nKey Words:\n" "[**Keywords**: ") (replace-all "\nKey Words: " "[**Keywords**: ") (replace-all "\nKey words\n" "[**Keywords**: ") (replace-all "\\[Key Words: " "[**Keywords**: ") (replace-all "\\[Key words: " "[**Keywords**: ") (replace-all "\\[KEYWORDS: " "[**Keywords**: ") (replace-all "\\[K E Y W O R D S: " "[**Keywords**: ") (query-replace "\nAbbreviations\n" "[**Abbreviations**: " nil begin end) (query-replace ".\n" ".\n\n**" nil begin end) (replace-all "\\[Keywords:" "\n\n[**Keywords**:") (replace-all "\\[Keyword(s):" "\n\n[**Keywords**:") ) (replace-all ","" "",") (replace-all ";"" "";") (replace-all " " " " "") (replace-all " \\?"" "?"") (replace-all " I Q " " IQ ") (query-replace "."" ""." nil begin end) (query-replace " : " ": " nil begin end) (replace-all ",\"" "\",") (replace-all ";\"" "\";") (replace-all "\n\n\n" "\n\n") (replace-all ": " ": ") (replace-all " > " "\n- ") (replace-all "\n> " "\n- ") (replace-all " yr\\." " years.") (replace-all "Calif\\." "California") (replace-all "Previous article in issueNext article in issue" "") (replace-all "Previous article in issue\nNext article in issue" "") (replace-all "\nAbstract\n" "\n") (replace-all "statistical significance" "statistical-significance") (replace-all "statistically significant" "statistically-significant") (replace-all "Statistically significant" "Statistically-significant") (replace-all "clinical significance" "clinical-significance") (replace-all "clinically significant" "clinically-significant") (replace-all "statistically different" "statistically-significantly different") (replace-all "statistical difference" "statistically-significant difference") (replace-all "type I error rate" "false positive rate") (replace-all "type II error rate" "false negative rate") (replace-all "genome-wide significant" "genome-wide statistically-significant") (replace-all "genome-wide significance" "genome-wide statistical-significance") (funcall-interactively #'query-replace-regexp " significantly" (query-replace-compile-replacement "\\,(let* ((replacements '((?1 \" statistically-significantly\") (?2 \" importantly\") (?3 \" largely\") (?4 \" substantially\"))) (choice (read-multiple-choice \"Replace: \" replacements))) (second choice))" t) nil begin end) (funcall-interactively #'query-replace-regexp " significant" (query-replace-compile-replacement "\\,(let* ((replacements '((?1 \" statistically-significant\") (?2 \" important\") (?3 \" large\") (?4 \" substantial\"))) (choice (read-multiple-choice \"Replace: \" replacements))) (second choice))" t) nil begin end) (funcall-interactively #'query-replace-regexp " significance" (query-replace-compile-replacement "\\,(let* ((replacements '((?1 \" statistical-significance\") (?2 \" importance\") (?3 \" large\"))) (choice (read-multiple-choice \"Replace: \" replacements))) (second choice))" t) nil begin end) (query-replace "non-significantly" "non-statistically-significantly" nil begin end) (query-replace "non-significance" "non-statistical-significance" nil begin end) (query-replace "nonsignificant" "non-statistically-significant" nil begin end) (query-replace " Homo habilis" " _Homo habilis_" nil begin end) (query-replace " Homo erectus" " _Homo erectus_" nil begin end) (query-replace " Homo " " _Homo_ " nil begin end) (query-replace "https://www.gwern.net/" "https://gwern.net/" nil begin end) (query-replace "https://gwern.net/" "/" nil begin end) (query-replace "\nhat " "\nWhat" nil begin end) ; shout-out to typography nerds by using the proper logotypes: (let ((case-fold-search t) (search-upper-case t)) ; need these to override `query-replace` magic!? (query-replace "P > 0" "_p_ > 0" nil begin end) (query-replace "p < " "_p_ <" nil begin end) (query-replace "P <= " "_p_ <= " nil begin end) (query-replace "p<" "_p_ < " nil begin end) (query-replace-regexp "[^u]p>" "_p_ > " nil begin end) ; avoid '' (query-replace "p < " "_p_ <" nil begin end) (query-replace "P < " "_p_ <" nil begin end) (query-replace "P<" "_p_ <" nil begin end) (query-replace "P <" "_p_ <" nil begin end) (query-replace "_P_ <" "_p_ <" nil begin end) (query-replace "_P_<" "_p_ <" nil begin end) (query-replace "_p_=." "_p_ = 0." nil begin end) (query-replace "_p_<." "_p_ < 0." nil begin end) (query-replace "_p_ <." "_p_ < 0." nil begin end) (query-replace "( _p_ = " "(_p_ = " nil begin end) (query-replace "<0." " < 0." nil begin end) (query-replace "p = " "_p_ = " nil begin end) (query-replace "( P = " "(_p_ = " nil begin end) (query-replace " P < " " _p_ < " nil begin end) (query-replace "P-for-interaction" "_p_-for-interaction" nil begin end) (query-replace " p = " " _p_ = " nil begin end) (query-replace "(ps " "(ps " nil begin end) (query-replace "k-NN" "_k_-NN" nil begin end) (query-replace "" "_r_" nil begin end) (query-replace "Sect\\. " "Section " nil begin end) (query-replace "rSDS" "r~SDS~" nil begin end) (query-replace "tpre-Neolithic" "tpre-Neolithic" nil begin end) (query-replace "tNearEast" "tNear East" nil begin end) (query-replace "tNeolithic" "tNeolithic" nil begin end) (query-replace " b = " " _b_ = " nil begin end) (query-replace "(b = " "(_b_ = " nil begin end) (query-replace "[b=" "[_b_ =" nil begin end) (query-replace "[b = " "[_b_ =" nil begin end) (query-replace "b=" "_b_ =" nil begin end) (query-replace "_b_=" "_b_ =" nil begin end) (query-replace "(b=" "(_b_ =" nil begin end) (query-replace " t <" " _t_ <" nil begin end) (query-replace " t =" " _t_ =" nil begin end) (query-replace "(t =" "(_t_ =" nil begin end) (query-replace "(t=" "(_t_ = " nil begin end) (query-replace " t-test" " _t_-test" nil begin end) (query-replace " t test" " _t_-test" nil begin end) (query-replace "(t test" "(_t_-test" nil begin end) (query-replace " R2 " " R^2^ " nil begin end) (query-replace "(R2 " "(R^2^ " nil begin end) (query-replace "R2=" " R^2^ =" nil begin end) (query-replace "R2<" " R^2^ <" nil begin end) (query-replace "R2>" " R^2^ <" nil begin end) (query-replace "r2" "R^2^" nil begin end) (query-replace "r2" "R^2^" nil begin end) (query-replace "r^2^" "R^2^" nil begin end) (query-replace "kh2" "kh^2^" nil begin end) (query-replace "mm 2" "mm^2^" nil begin end) (query-replace "age2" "age^2^" nil begin end) (query-replace "m-2" "m^-2^" nil begin end) (query-replace "rxy " "rxy" nil begin end) (query-replace "n-of-1" "n-of-1" nil begin end) (query-replace " g = " " _g_ = " nil begin end) (query-replace " g's" " _g_'s" nil begin end) (query-replace "(g " "(_g_ " nil begin end) (query-replace " g)" " _g_)" nil begin end) (query-replace "(m = " "(_m_ =" nil begin end) (query-replace "LaTeX" "LaTeX" nil begin end) ; LaTeX (query-replace "LATEX" "LaTeX" nil begin end) (query-replace "TeX" "TeX" nil begin end) ; TeX (query-replace "TEX" "TeX" nil begin end) (query-replace-regexp "^\\.\\.\\.he" "...The" nil begin end) ; very common to truncate in copy-paste ) ; end case-fold let (should create strict case-matching?) (query-replace "Nepeta cataria" "_Nepeta cataria_" nil begin end) (query-replace "MC4R" "_MC4R_" nil begin end) (query-replace "GPT2" "GPT-2" nil begin end) (query-replace "GPT3" "GPT-3" nil begin end) (query-replace "GPT4" "GPT-4" nil begin end) (query-replace "two thirds" "2/3" nil begin end) (query-replace "two-thirds" "2/3" nil begin end) (query-replace "three-fourths" "3/4" nil begin end) (query-replace "3-fourths" "3/4" nil begin end) (query-replace "three-fifths" "3/5" nil begin end) (query-replace-regexp "\\([0-9]+\\) of \\([0-9]+\\)" "\\1/\\2" nil begin end) (query-replace-regexp "\\([0-9]+\\) of the \\([0-9][0-9]?[0-9]?\\)" "\\1/\\2" nil begin end) (query-replace-regexp " \\([0-9][0-9]?[0-9]?\\) of \\([0-9][0-9]?[0-9]?\\) " " \\1/\\2 " nil begin end) (query-replace-regexp "\\([0-9]+\\) out of \\([0-9][0-9]?[0-9]?\\)" "\\1/\\2" nil begin end) (query-replace-regexp "\\([0-9]+\\) out of the \\([0-9][0-9]?[0-9]?\\)" "\\1/\\2" nil begin end) (query-replace-regexp "\\([0-9]+\\) in every \\([0-9]+\\)" "\\1/\\2" nil begin end) ; eg. "approximately one in every 10 citations across leading psychology journals is inaccurate" (query-replace-regexp " \\([0-9]+\\)%" "\\1%" nil begin end) ; "to 15% for heroin" (query-replace "...." "..." nil begin end) (query-replace "....." "..." nil begin end) (query-replace-regexp "\n\\.\\.\\([A-Za-z]\\)" "\n...\\1" nil begin end) ; replace malformed '...' ellipsis excerpts (query-replace-regexp "^\\.\\.\\. " "..." nil begin end) (query-replace " = ." " = 0." nil begin end) (query-replace " Ss" " Subjects" nil begin end) ; PsycNET APA abbreviations (query-replace-regexp "\\([Ee]\\)xp\\(s?\\) " "\\1xperiment\\2 " nil begin end) (query-replace-regexp " (PsycInfo Database Record (c) [12][0-9]+ APA, all rights reserved)" "" nil begin end) ; PsycNET copyright junk ; (query-replace " * " ", " nil begin end) ; some 'Keywords' sections are always MIDDLE DOT formatted (query-replace-regexp "\\([0-9]+\\)*\\([0-9]+\\)" "\\1.\\2" nil begin end) ; mostly for the Lancet (query-replace "Figs. " "Figures " nil begin end) (query-replace "Fig. " "Figure " nil begin end) (query-replace-regexp "Supplementary [fF]ig\\. \\(S?[0-9]+[a-hA-H]*\\)\\." "**Supplementary Figure \\1**." nil begin end) ; 'Supp Fig. 1. ', 'Fig. 2a)' etc (query-replace-regexp "Supplementary [fF]ig\\. \\(S?[0-9]+[a-hA-H]*\\)" "**Supplementary Figure \\1**" nil begin end) ; 'Supp Fig. 1,', 'Fig. 2a,' etc (query-replace-regexp "Supplementary [fF]igure \\(S?[0-9]+[a-hA-H]*\\)\\." "**Supplementary Figure \\1**." nil begin end) ; 'Supp Figure 1. The graph' etc (query-replace-regexp "Supplementary ([fF]ig\\. \\(S?[0-9]+[a-hA-H]*\\))" "(**Supplementary Figure \\1**)" nil begin end) ; (Supp Fig. 3b) (query-replace-regexp "Supplementary ([fF]igure \\(S?[0-9]+[a-hA-H]*\\))" "(**Supplementary Figure \\1**)" nil begin end) ; (Supp Figure 3b) (query-replace-regexp "Supplementary ([fF]ig\\. \\(S?[0-9]+[a-hA-H]*\\)," "(**Supplementary Figure \\1**," nil begin end) ; (Supp Fig. 3b, (query-replace-regexp "Supplementary [fF]igures \\(S?[0-9]+[a-hA-H]*\\) and \\([0-9]+[a-hA-H]*\\)" "**Supplementary Figures \\1** & **\\2**" nil begin end) (query-replace-regexp "[fF]ig\\.? ?\\(S?\\)\\([0-9\\.]+[a-hA-H]*\\)\\.?" "**Figure \\1\\2**." nil begin end) ; 'Fig. 1. ', 'Fig. 2a)', 'Figure 1.5' etc (query-replace-regexp "[fF]ig\\.? \\(S?\\)\\([0-9\\.]+[a-hA-H]*\\)" "**Figure \\1\\2**" nil begin end) ; 'Fig. 1,', 'Fig. 2a,' etc (query-replace-regexp "[fF]igure \\(S?\\)\\([0-9\\.]+[a-hA-H]*\\.?\\)" "**Figure \\1\\2**" nil begin end) ; 'Figure 1. The graph' etc (query-replace-regexp "([fF]ig\\.? \\(S?\\)\\([0-9\\.]+[a-hA-H]*\\))" "(**Figure \\1\\2**)" nil begin end) ; (Fig. 3b) (query-replace-regexp "([fF]igure \\(S?\\)\\([0-9\\.]+[a-hA-H]*\\))" "(**Figure \\1\\2**)" nil begin end) ; (Figure 3b) (query-replace-regexp "([fF]ig\\.? \\(S?\\)\\([0-9\\.]+[a-hA-H]*\\)," "(**Figure \\1\\2**," nil begin end) ; (Fig. S3b, (query-replace-regexp "[aA]ppendix.? ?\\([a-zA-Z]?\\)\\([0-9\\.]+[a-hA-H]*\\)" "**Appendix \\1\\2**" nil begin end) ; 'Appendix A2' (query-replace-regexp "[aA]ppendix.? \\([a-zA-Z]?\\)" "**Appendix \\1**" nil begin end) ; 'Appendix A' (query-replace-regexp "Equation \\([a-zA-Z0-9]+\\)" "**Equation \\1**" nil begin end) ; 'Equation 9', 'Equation C' ; 'SS SECTION SIGN' is better than writing out 'Section N' everywhere. It's much shorter, we already use SECTION SIGN heavily, it reduces overuse of bold, is easier to grep for, and it saves a bit of time formatting annotations (because of the lack of lookahead/lookbehind in these regexp rewrites, 'Section N' will match every time, even if it's already wrapped in /**bolding**, and I have to waste time skipping them). It would be nice to symbolize Figure/Table/Experiment/Data as well, but there's no widely-understood symbol which could be used, and usually no abbreviation either. (Perhaps 'Supplement.*' could be replaced by just 'S' and 'Figure' by 'Fig.' at some point...) (query-replace-regexp "[Ss]ection ?\\([0-9.]+[a-hA-H]*\\)" "SS\\1" nil begin end) ; 'Section 9' - 'SS9', 'section 9' - 'SS9' (query-replace-regexp "[Ss]ect\\. ?\\([0-9.]+[a-hA-H]*\\)" "SS\\1" nil begin end) ; 'Sect. 9' - 'SS9', 'sect. 9' - 'SS9' (query-replace-regexp "Part ?\\([0-9.]+[a-hA-H]*\\)" "SS\\1" nil begin end) ; 'Part 9' - 'SS9' (query-replace-regexp "[Ss]ections ?\\([0-9.]+[a-hA-H]*\\) and \\([0-9.]+[a-hA-H]*\\)" "SS\\1 & SS\\2" nil begin end) ; 'Sections 1 and 2' - 'SS1 & SS2' (query-replace-regexp "Chapter \\([0-9]+[a-hA-H]*\\)" "**Ch\\1**" nil begin end) ; 'Chapter 1', 'Chapter 7a' etc (query-replace-regexp "Supplementary [Tt]able\\.? \\([0-9]+[a-hA-H]*\\)\\." "**Supplementary Table \\1**." nil begin end) ; 'Table. 1. ', 'Table. 2a)' etc (query-replace-regexp "Supplementary [Tt]able\\.? \\([0-9]+[a-hA-H]*\\)" "**Supplementary Table \\1**" nil begin end) ; 'Table. 1,', 'Table. 2a,' etc (query-replace-regexp "Supplementary [Tt]able \\([0-9]+[a-hA-H]*\\)\\." "**Supplementary Table \\1**:" nil begin end) ; 'Table 1. The graph' etc (query-replace-regexp "Supplementary ([Tt]able\\. \\([0-9]+[a-hA-H]*\\))" "(**Supplementary Table \\1**)" nil begin end) ; (Table. 3b) (query-replace-regexp "Supplementary ([Tt]able \\([0-9]+[a-hA-H]*\\))" "(**Supplementary Table \\1**)" nil begin end) ; (Table 3b) (query-replace-regexp "Supplementary ([Tt]able\\. \\([0-9]+[a-hA-H]*\\)," "(**Supplementary Table \\1**," nil begin end) ; (Table. 3b, (query-replace-regexp "Supplementary [Tt]ables \\([0-9]+[a-hA-H]*\\) and \\([0-9]+[a-hA-H]*\\)" "**Supplementary Tables \\1** & **\\2**" nil begin end) (query-replace-regexp "[Tt]ables?\\.? \\(S?[0-9]+[a-hA-H]*\\)\\." "**Table \\1**:" nil begin end) ; 'Table. 1. ', 'Table. 2a)' etc (query-replace-regexp "[Tt]ables?\\.? \\(S?[0-9]+[a-hA-H]*\\)" "**Table \\1**" nil begin end) ; 'Table. 1,', 'Table. 2a,' etc (query-replace-regexp "[Tt]ables?\\.? \\(S?[a-hA-H]+[0-9]+\\)" "**Table \\1**" nil begin end) ; 'Table S3' (query-replace-regexp "[Tt]ables? \\(S?[0-9]+[a-hA-H]*\\)\\." "**Table \\1**:" nil begin end) ; 'Table 1. The graph' etc (query-replace-regexp "([Tt]ables?\\.? \\(S?[0-9]+[a-hA-H]*\\))" "(**Table \\1**)" nil begin end) ; (Table. 3b) (query-replace-regexp "([Tt]ables? \\(S?[0-9]+[a-hA-H]*\\))" "(**Table \\1**)" nil begin end) ; (Table 3b) (query-replace-regexp "([Tt]ables?\\.? \\(S?[0-9]+[a-hA-H]*\\)," "(**Table \\1**," nil begin end) ; (Table. 3b, (query-replace-regexp "[Tt]ables?\\.? \\(S?[0-9]+[a-hA-H]*\\) and \\([0-9]+[a-hA-H]*\\)" "**Table \\1** & **\\2**" nil begin end) ; 'Tables 9 and 10' (query-replace-regexp "[Ee]xperiment \\([0-9]+[a-hA-H]*\\)" "**Experiment \\1**" nil begin end) ; 'Experiment 1', 'Experiment 2a', 'experiment 3' etc (query-replace "Experiments 1 and 2" "**Experiments 1** & **2**" nil begin end) (query-replace-regexp "[Ss]tudy \\([0-9]+[a-hA-H]*\\)" "**Study \\1**" nil begin end) (query-replace-regexp "[Ss]tudies \\([0-9]+[a-hA-H]*\\)[--]+\\([0-9]+[a-hA-H]*\\)" "**Studies \\1--\\2**" nil begin end) (query-replace-regexp "[Ss]tudies \\([0-9]+[a-hA-H]*\\) and \\([0-9]+[a-hA-H]*\\)" "**Studies \\1** & **\\2**" nil begin end) (query-replace-regexp "[Ss]tudies \\([0-9]+[a-hA-H]*\\), \\([0-9]+[a-hA-H]*\\), and \\([0-9]+[a-hA-H]*\\)" "**Studies \\1**, **\\2**, & **\\3**" nil begin end) (query-replace-regexp "[Ss]tudies \\([0-9]+[a-hA-H]*\\), \\([0-9]+[a-hA-H]*\\), \\([0-9]+[a-hA-H]*\\)" "**Studies \\1**, **\\2**, **\\3**" nil begin end) (query-replace-regexp "^\\( *\\)\\([0-9]+\\)\\. " "\\1#. " nil begin end) ; Markdown ordered-list number formatting: see default.css for more discussion, but using '1./2./3.' list numbering in Markdown yields hardwired number formatting rather than plain `" "
") (replace-all "
" "") ; (replace-all "" "
\n") ; (replace-all "
" "
\n") (replace-all " id=\"cb1\">" "") ; the Pandoc syntax-highlighting IDs cause ID clashes when substituted into pages, so delete all (replace-all " id=\"cb2\">" "") (replace-all " id=\"cb3\">" "") (replace-all " id=\"cb4\">" "") (replace-all "
" "\" />") (replace-all "''" "'") (replace-all "'s" "'s") (replace-all "%3Csup%3Est%3C/sup%3E" "th") (replace-all "%3Csup%3End%3C/sup%3E" "nd") (replace-all "%3Csup%3Erd%3C/sup%3E" "rd") (replace-all "" "") ; unnecessary in annotations for WP links because they will be regenerated by the single-source-of-truth: (replace-all " class=\"id-not link-live\"" "") (replace-all "class=\"id-not link-live\"" "") (delete-trailing-whitespace) (forward-line) (html-mode) (my-frame-urgent-hint-set) ; XMonad is set to use XMonad.Hooks.UrgencyHook.withUrgencyHook's FocusHook to yank focus to X11 frames with urgent hint set (ding) (message "Done.") ) ) ) ) (add-hook 'markdown-mode-hook (lambda () (define-key markdown-mode-map "\C-c\ w" 'markdown-annotation-compile))) (defvar html-mode-map) ; suppress reference-to-free-variable byte-compile warning (add-hook 'html-mode-hook (lambda () (define-key html-mode-map "\C-c\ w" 'markdown-annotation-compile))) ; for the `foo` buffer I do most of my annotation work in, on the first copy-paste of a block of text, detect if it has any paragraph breaks (ie. double newlines), and if it does not, then automatically run paragraphizer.py on it to try to break it up into logical paragraphs. (defun markdown-paragraphize () "Automatically paragraphize single-paragraph abstracts. Intended for Markdown mode with double-newlines for newlines; may malfunction if run on other formats like HTML \(where `` pairs can come in many forms, not to mention other block elements like blockquotes\)."
(interactive)
(delete-trailing-whitespace)
(let ((double-newline-found nil))
(save-excursion
(goto-char (point-min))
(unless (search-forward-regexp "\n\n" nil t)
(message "Paragraphizing abstract...")
(let* ((paragraphizer-path (executable-find "paragraphizer.py"))
(original-text (buffer-substring-no-properties (point-min) (point-max)))
(original-length (length original-text)))
(if paragraphizer-path
(progn
; NOTE: we do *not* want to capture stderr output
(call-process-region (point-min) (point-max) paragraphizer-path t (list t nil) nil)
(let* ((new-length (- (point-max) (point-min)))
(has-double-newline (save-excursion
(goto-char (point-min))
(search-forward-regexp "\n\n" nil t))))
(if (and (>= new-length original-length)
has-double-newline)
(progn
(setq double-newline-found t)
(message "Paragraphizing abstract done. New text is valid (%d chars, has paragraphs)." new-length))
(progn
(delete-region (point-min) (point-max))
(insert original-text)
(message "Paragraphizing skipped: new text invalid [char-length change: %d - %d, has \\n\\n: %s]."
original-length new-length (if has-double-newline "True" "False"))))))
(error "Error: Python `paragraphizer.py` script not found in path")))))
(when double-newline-found
(goto-char (point-max)))))
(defun markdown-paragraphize-hook ()
"Hook function for `markdown-paragraphize`."
(when (and (equal (buffer-name) "foo")
(derived-mode-p 'markdown-mode)
(eq this-command 'yank)
(>= (buffer-size) 500)) ; ensure that there is enough in the buffer to plausibly be a full copy-pasted abstract, as opposed to a random snippet or line.
(markdown-paragraphize)))
(add-hook 'post-command-hook #'markdown-paragraphize-hook)
; https://emacs.stackexchange.com/a/56037
(defun my-frame-urgent-hint-set--for-x11 (frame arg &optional window-id)
"Set the x11-urgency hint for the FRAME to ARG (on WINDOW-ID) :
- If ARG is nil, unset the urgency.
- If ARG is any other value, set the urgency.
If you unset the urgency, you still have to visit the frame to reset it."
(let* ((wm-prop "WM_HINTS") ;; Constants.
(wm-flag-urgent #x100)
(wm-hints (append (x-window-property wm-prop frame wm-prop window-id nil t) nil))
(flags (car wm-hints)))
(setcar wm-hints
(if arg
(logior flags wm-flag-urgent)
(logand flags (lognot wm-flag-urgent))))
(x-change-window-property wm-prop wm-hints frame wm-prop 32 t)))
(defun my-frame-urgent-hint-set (&optional arg)
"Mark the current Emacs frame as requiring urgent attention.
With prefix argument ARG which is not boolean value nil, remove urgency
\(which might or might not change display, depending on the window manager\)."
(interactive "P")
(let*
(
(frame (selected-frame))
(win-system (window-system frame)))
(cond
((eq win-system 'x)
(my-frame-urgent-hint-set--for-x11 frame (not arg)))
;; only Linux X11 is supported:
(t
(message "Urgent hint for window system %S unsupported" win-system)))))
; add new-line / paragraph snippet
(add-hook 'html-mode-hook
(lambda ()
(define-key html-mode-map (kbd "
")
(if (= ?\s (following-char)) (delete-char 1)))
)
))
(add-hook 'markdown-mode-hook 'visual-fill-column-mode)
;; Markup editing shortcuts for HTML/Markdown/GTX annotation editing.
;; Functions to easily add italics, bold, Wikipedia links, smallcaps, & margin-note syntax.
(defun surround-region-or-word (start-tag end-tag)
"Surround region (or next word) with START-TAG and END-TAG.
If the previous command was this command, remove the end tag before point,
skip any leading whitespace, move forward one word (within the same line),
and insert only the end tag.
This allows repeating the keybinding to incrementally mark up a region
by bubbling the end-tag through the line."
(interactive)
(if (eq last-command 'surround-region-or-word)
;; Repeated invocation: extend the existing formatted region.
(let ((end-tag-len (length end-tag)))
;; Verify the text immediately before point is the end tag.
(if (and (>= (point) end-tag-len)
(string= (buffer-substring-no-properties (- (point) end-tag-len) (point))
end-tag))
(delete-region (- (point) end-tag-len) (point))
(error "Expected end tag not found"))
;; Skip any whitespace before moving to the next word, for better compatibility with word-level movement like `C-f`:
(skip-chars-forward " \t")
;; Move forward one word, but avoid crossing a newline.
(unless (or (eolp) (looking-at "\n"))
(forward-word))
(insert end-tag))
;; First invocation: wrap region (or next word) with start and end tags.
(let* ((beg (if (use-region-p)
(region-beginning)
(progn
(skip-chars-forward " \t")
(point))))
(end (if (use-region-p)
(region-end)
(progn (forward-word) (point)))))
(goto-char end)
(insert end-tag)
(goto-char beg)
(insert start-tag)
;; Position point after the inserted tags.
(goto-char (+ end (length start-tag) (length end-tag)))
(deactivate-mark)))
(setq this-command 'surround-region-or-word))
;; the wrappers:
(defun html-insert-emphasis ()
"Surround selected region (or word) with HTML tags for italics/emphasis (also Markdown, which supports `*FOO*`)."
(interactive)
(surround-region-or-word "" ""))
(defun markdown-insert-emphasis ()
"Surround selected region (or word) with Markdown asterisks for italics/emphasis.
Equivalent to `FOO` in HTML.
Gwern.net uses `*` for emphasis, and generally reserves `_` for italics such as book titles
(in keeping with Internet conventions predating Gruber's Markdown mistake of conflating `*`/`_`)."
(interactive)
(surround-region-or-word "*" "*"))
(defun html-insert-strong ()
"Surround selected region (or word) with bold tags (HTML, equivalent to `**` in Markdown).
Used in abstracts for topics, first-level list emphasis, etc."
(interactive)
(surround-region-or-word "" ""))
(defun markdown-insert-strong ()
"Surround selected region (or word) with `**` bold tags (Markdown).
Equivalent to `FOO` in HTML.
Used in abstracts for topics, first-level list emphasis, etc."
(interactive)
(surround-region-or-word "**" "**"))
(defun html-insert-smallcaps ()
"Surround selected region (or word) with smallcaps syntax.
Built-in CSS class in HTML & Pandoc Markdown, span syntax is equivalent to
`[FOO]{.smallcaps}`.
Smallcaps are used on Gwern.net for second-level emphasis after bold has been used."
(interactive)
(surround-region-or-word "" ""))
(defun markdown-insert-smallcaps ()
"Surround selected region (or word) with smallcaps syntax (Pandoc Markdown).
Built-in CSS class in HTML & Pandoc Markdown, equivalent to
`FOO`.
Smallcaps are used on Gwern.net for second-level emphasis after bold has been used."
(interactive)
(surround-region-or-word "[" "]{.smallcaps}"))
(defun html-insert-wp-link ()
"Surround selected region (or word) with custom Wikipedia link syntax in HTML.
Compiled by Interwiki.hs to the equivalent (usually) of `FOO`."
(interactive)
(surround-region-or-word "" ""))
(defun markdown-insert-wp-link ()
"Surround selected region (or word) with custom Wikipedia link syntax in Markdown."
(interactive)
(surround-region-or-word "[" "](!W)"))
(defun markdown-insert-margin-note ()
"Surround selected region FOO BAR (or word FOO) with a `margin-note`.
\(Implemented as a special `` class.\)
This creates marginal glosses (in the left margin) as counterparts to sidenotes.
These margin-notes are used as very abbreviated italicized summaries of the
paragraph \(like very small inlined section headers\)."
(interactive)
(surround-region-or-word "[" "]{.marginnote}"))
(defun html-insert-margin-note ()
"Surround selected region FOO BAR (or word FOO) with a `margin-note`.
\(Implemented as a special `` HTML class.\)
This creates marginal glosses (in the left margin) as counterparts to sidenotes.
These margin-notes are used as very abbreviated italicized summaries of the
paragraph \(like very small inlined section headers\).
When inserting margin-notes into HTML snippets, that usually means an annotation
and the margin-note is an editorial insertion, which are denoted by paired `[]` brackets.
To save typing effort, we add those as well if not present."
(interactive)
(let ((content (if (use-region-p)
(buffer-substring-no-properties (region-beginning) (region-end))
(thing-at-point 'word t))))
(if (and (string-prefix-p "[" content) (string-suffix-p "]" content))
(surround-region-or-word "" "")
(surround-region-or-word "[" "]"))))
(defun markdown-insert-editorial-note ()
"Surround selected region (or word) with editorial syntax.
Used on Gwern.net to denote 'editorial' insertions like commentary
or annotations. Markdown version.
For existing bracketed regions, they will be Markdown-escaped to
reduce risk of syntax breakage from double-brackets like '\[\[';
see for more discussion."
(interactive)
(let* ((beg (if (use-region-p)
(region-beginning)
(progn
(skip-chars-forward " \t")
(point))))
(end (if (use-region-p)
(region-end)
(save-excursion (forward-word) (point))))
(content (buffer-substring-no-properties beg end))
(escaped (replace-regexp-in-string "\\]" "\\]"
(replace-regexp-in-string "\\[" "\\[" content nil t) nil t)))
(delete-region beg end)
(goto-char beg)
(insert "[" escaped "]{.editorial}")
(deactivate-mark)))
(defun html-insert-editorial-note ()
"Surround selected region FOO BAR (or word FOO) with `editorial note`.
\(Implemented as a special `` HTML class.\)
This is for editorial insertions like commentary.
When inserting editorial notes into HTML snippets,
that usually means an annotation and
the editorial-note is an editorial insertion,
which are denoted by paired `[]` brackets.
To save typing effort, we add those as well if not present.
See also margin-notes ('html-insert-margin-note', 'markdown-insert-margin-note')."
(interactive)
(let ((content (if (use-region-p)
(buffer-substring-no-properties (region-beginning) (region-end))
(thing-at-point 'word t))))
(if (and (string-prefix-p "[" content) (string-suffix-p "]" content))
(surround-region-or-word "" "") ; NOTE: we skip quotes to make it litt safer for use in annotations given that they get substituted into figure captions sometimes
(surround-region-or-word "[" "]"))))
;; keybindings:
;;; Markdown:
(add-hook 'markdown-mode-hook (lambda()(define-key markdown-mode-map "\C-c\ \C-e" 'markdown-insert-emphasis)))
(add-hook 'markdown-mode-hook (lambda()(define-key markdown-mode-map "\C-c\ \C-s" 'markdown-insert-strong)))
(add-hook 'markdown-mode-hook (lambda()(define-key markdown-mode-map "\C-c\ s" 'markdown-insert-smallcaps)))
(add-hook 'markdown-mode-hook (lambda()(define-key markdown-mode-map "\C-c\ \C-w" 'markdown-insert-wp-link)))
(add-hook 'markdown-mode-hook (lambda()(define-key markdown-mode-map "\C-c\ \C-m" 'markdown-insert-margin-note)))
(add-hook 'markdown-mode-hook (lambda()(define-key markdown-mode-map "\C-c\ e" 'markdown-insert-editorial-note)))
;;; HTML:
(add-hook 'html-mode-hook (lambda()(define-key html-mode-map "\C-c\ \C-e" 'html-insert-emphasis)))
(add-hook 'html-mode-hook (lambda()(define-key html-mode-map "\C-c\ \C-s" 'html-insert-strong)))
(add-hook 'html-mode-hook (lambda()(define-key html-mode-map "\C-c\ s" 'html-insert-smallcaps)))
(add-hook 'html-mode-hook (lambda()(define-key html-mode-map "\C-c\ \C-w" 'html-insert-wp-link)))
(add-hook 'html-mode-hook (lambda()(define-key html-mode-map "\C-c\ \C-m" 'html-insert-margin-note)))
(add-hook 'html-mode-hook (lambda()(define-key html-mode-map "\C-c\ e" 'html-insert-editorial-note)))
;sp
; (add-hook 'markdown-mode-hook 'flyspell)
;for toggling visibility of sections - makes big pages easier to work with
(add-hook 'markdown-mode-hook 'outline-minor-mode)
;In Markdown files, there are few excuses for unbalanced delimiters, and unbalance almost always indicates a link syntax error; in cases where quoted text must contain unbalanced delimiters (eg diffs, or neural-net-generated text or redirects fixing typos), a matching delimiter can be added in a comment like '' to make it add up.
(defun balance-parens () (when buffer-file-name
(add-hook 'after-save-hook
'check-parens
nil t)))
(add-hook 'markdown-mode-hook 'balance-parens)
(add-hook 'ledger-mode-hook 'balance-parens)
(add-hook 'emacs-lisp-mode-hook 'balance-parens)
(add-hook 'haskell-mode-hook 'balance-parens)
(add-hook 'css-mode-hook 'balance-parens)
(add-hook 'javascript-mode-hook 'balance-parens)
(add-hook 'html-mode-hook 'balance-parens)
(add-hook 'python-mode-hook 'balance-parens)
; Insert the secondary X clipboard at point (handles Unicode correctly); works better than `xclip -o`.
; Trims whitespace (spurious whitespace is often added by X GUI programs like Firefox eg. double-clicking HTML headers or page titles, requiring tedious manual deletion).
(global-set-key "\M-`" #'(lambda () (interactive)
(insert-for-yank
(gui-get-selection 'PRIMARY 'UTF8_STRING))))
; Trim spurious whitespace from other X GUI copy-pastes as well.
; (We do not attempt to hook `yank` and run this on *all* copy-paste-like behavior, because deleting whitespace could seriously interfere with document or programming modes.)
(defun my-trim-gui-selection (orig-fun &rest args)
"Trim whitespace from text selected via GUI before yanking into Emacs.
Runs ORIG-FUN on ARGS to create the selected text (ie. original `gui-get-selection` + args)."
(let ((selection (apply orig-fun args)))
(if (stringp selection)
(string-trim selection)
selection)))
(advice-add 'gui-get-selection :around #'my-trim-gui-selection)
; ispell: ignore code blocks in Pandoc Markdown
; TODO: add a fix for '#' not being handled in URLs. current hack borrowed from