|
| 1 | +using LaTeXStrings, Unitful, Latexify, tectonic_jll |
| 2 | + |
| 3 | +commands = [ |
| 4 | + :(latexify(612.2u"nm")), |
| 5 | + :(latexify(u"kg*m/s^2")), |
| 6 | + :(latexify(612.2u"nm"; fmt=SiunitxNumberFormatter())), |
| 7 | + :(latexify(u"kg*m/s^2"; fmt=SiunitxNumberFormatter())), |
| 8 | + :(latexify(612.2u"nm"; fmt=SiunitxNumberFormatter(; simple=true))), |
| 9 | + :(latexify(u"kg*m/s^2"; fmt=SiunitxNumberFormatter(; simple=true))), |
| 10 | + :(latexify((1, 2, 4) .* u"m"; fmt=SiunitxNumberFormatter())), |
| 11 | +] |
| 12 | +tab1 = map(commands) do command |
| 13 | + LaTeXString.([ |
| 14 | + "\\verb+$(string(command))+", |
| 15 | + "\\verb+$(eval(command))+", |
| 16 | + "$(eval(command)) ", |
| 17 | + ]) |
| 18 | +end |
| 19 | +ltab1 = latextabular(tab1, adjustment=:l, transpose=true, latex=false, booktabs=true, |
| 20 | + head=["julia", "\\LaTeX", "Result"]) |
| 21 | +# Setting an explicit white background color results in transparent PDF, so go offwhite. |
| 22 | +ltab1 = LaTeXString("\\definecolor{offwhite}{rgb}{0.999,0.999,0.999}\n\\pagecolor{offwhite}\n\\color{black}\n" * ltab1) |
| 23 | + |
| 24 | +render(ltab1, MIME("image/png"); use_tectonic=true, |
| 25 | + name=(@__DIR__)*"/src/assets/latex-examples", |
| 26 | + packages=["booktabs", "color", "siunitx"], |
| 27 | + documentclass=("standalone")) |
| 28 | + |
| 29 | +functions = [ |
| 30 | + x -> "\\verb+$(string(x))+", |
| 31 | + x -> latexify(x), |
| 32 | + x -> latexify(x; fmt=SiunitxNumberFormatter()), |
| 33 | + x -> latexify(x; fmt=SiunitxNumberFormatter(; simple=true)), |
| 34 | +] |
| 35 | +allunits = begin |
| 36 | + uparse.([ |
| 37 | + "nH*m/Hz", |
| 38 | + "m", |
| 39 | + "s", |
| 40 | + "A", |
| 41 | + "K", |
| 42 | + "cd", |
| 43 | + "g", |
| 44 | + "mol", |
| 45 | + "sr", |
| 46 | + "rad", |
| 47 | + "°", |
| 48 | + "Hz", |
| 49 | + "N", |
| 50 | + "Pa", |
| 51 | + "J", |
| 52 | + "W", |
| 53 | + "C", |
| 54 | + "V", |
| 55 | + "S", |
| 56 | + "F", |
| 57 | + "H", |
| 58 | + "T", |
| 59 | + "Wb", |
| 60 | + "lm", |
| 61 | + "lx", |
| 62 | + "Bq", |
| 63 | + "Gy", |
| 64 | + "Sv", |
| 65 | + "kat", |
| 66 | + #"percent", # Messes with comments |
| 67 | + # "permille", # Undefined in all formats |
| 68 | + # "pertenthousand", # Undefined in all formats (butchered) |
| 69 | + "°C", |
| 70 | + "°F", # No longer in siunitx |
| 71 | + "minute", |
| 72 | + "hr", |
| 73 | + "d", |
| 74 | + "wk", # Undefined in siunitx |
| 75 | + "yr", # Undefined in siunitx |
| 76 | + "rps", # Undefined in siunitx |
| 77 | + "rpm", # Undefined in siunitx |
| 78 | + "a", # Undefined in siunitx |
| 79 | + "b", |
| 80 | + "L", |
| 81 | + "M", # Undefined in siunitx |
| 82 | + "eV", |
| 83 | + "Hz2π", # Butchered by encoding |
| 84 | + "bar", |
| 85 | + "atm", # Undefined in siunitx |
| 86 | + "Torr", # Undefined in siunitx |
| 87 | + "c", # Undefined in siunitx |
| 88 | + "u", # Undefined in siunitx |
| 89 | + "ge", # Undefined in siunitx |
| 90 | + "Gal", # Undefined in siunitx |
| 91 | + "dyn", # Undefined in siunitx |
| 92 | + "erg", # Undefined in siunitx |
| 93 | + "Ba", # Undefined in siunitx |
| 94 | + "P", # Undefined in siunitx |
| 95 | + "St", # Undefined in siunitx |
| 96 | + #"Gauss", # errors in testing, maybe from Unitful.jl's dev branch? |
| 97 | + #"Oe", # errors in testing, maybe from Unitful.jl's dev branch? |
| 98 | + #"Mx", # errors in testing, maybe from Unitful.jl's dev branch? |
| 99 | + "inch", # Undefined in siunitx |
| 100 | + "mil", # Undefined in siunitx |
| 101 | + "ft", # Undefined in siunitx |
| 102 | + "yd", # Undefined in siunitx |
| 103 | + "mi", # Undefined in siunitx |
| 104 | + "angstrom", # Undefined in mathrm,siunitxsimple |
| 105 | + "ac", # Undefined in siunitx |
| 106 | + "Ra", # Undefined in siunitx |
| 107 | + "lb", # Undefined in siunitx |
| 108 | + "oz", # Undefined in siunitx |
| 109 | + "slug", # Undefined in siunitx |
| 110 | + "dr", # Undefined in siunitx |
| 111 | + "gr", # Undefined in siunitx |
| 112 | + "lbf", # Undefined in siunitx |
| 113 | + "cal", # Undefined in siunitx |
| 114 | + "btu", # Undefined in siunitx |
| 115 | + "psi", # Undefined in siunitx |
| 116 | + #"dBHz", # Cannot *yet* be latexified. |
| 117 | + #"dBm", # Cannot *yet* be latexified. |
| 118 | + #"dBV", # Cannot *yet* be latexified. |
| 119 | + #"dBu", # Cannot *yet* be latexified. |
| 120 | + #"dBμV", # Cannot *yet* be latexified. |
| 121 | + #"dBSPL", # Cannot *yet* be latexified. |
| 122 | + #"dBFS", # Cannot *yet* be latexified. |
| 123 | + #"dBΩ", # Cannot *yet* be latexified. |
| 124 | + #"dBS", # Cannot *yet* be latexified. |
| 125 | + ]) |
| 126 | +end |
| 127 | + |
| 128 | +tab2 = map(allunits) do unit |
| 129 | + [LaTeXString(f(unit)) for f in functions] |
| 130 | +end |
| 131 | +ltab2 = latextabular(tab2, adjustment=:l, transpose=true, latex=false, booktabs=true, |
| 132 | + head=["Name", "Default number formatter", "\\verb+SiunitxNumberFormatter()+", "\\verb+SiunitxNumberFormatter(;simple=true)+"]) |
| 133 | +# Set background to not-quite-white so it doesn't get treated as transparent |
| 134 | +ltab2 = LaTeXString( |
| 135 | + """ |
| 136 | + \\setmainfont{FreeSerif} |
| 137 | + \\setmonofont{FreeMono} |
| 138 | + \\definecolor{offwhite}{rgb}{0.999,0.999,0.999} |
| 139 | + \\pagecolor{offwhite} |
| 140 | + \\color{black} |
| 141 | + """ * ltab2) |
| 142 | + |
| 143 | +render(ltab2, MIME("image/png"); use_tectonic=true, |
| 144 | + tectonic_flags=`-Z continue-on-errors`, |
| 145 | + name=(@__DIR__)*"/src/assets/latex-allunits", |
| 146 | + packages=["booktabs", "color", "siunitx", "fontspec"], |
| 147 | + documentclass=("standalone")) |
0 commit comments