Skip to content

Commit

Permalink
Add powertick for hidden LaTeX (#92)
Browse files Browse the repository at this point in the history
* Add powertick for hidden LaTeX
  • Loading branch information
tmigot authored Feb 9, 2023
1 parent 8e55075 commit a6b2e7f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/BenchmarkProfiles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,20 @@ Examples:
powertick("15") == "2¹⁵"
powertick("2.1") == "2²⋅¹"
powertick("\$0\$") == "\$2^0\$"
"""
function powertick(s::AbstractString)
codes = Dict(collect(".1234567890") .=> collect("⋅¹²³⁴⁵⁶⁷⁸⁹⁰"))
return "2" * map(c -> codes[c], s)
hidden_latex = !isnothing(match(r"^\$.*\$$", s))
ex = r"[0-9.]+"
for m eachmatch(ex, s)
s = if hidden_latex
replace(s, m.match => "2^{$(m.match)}")
else
replace(s, m.match => "2" * map(c -> codes[c], m.match))
end
end
return s
end

"""
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ using Test
@testset "powertick" begin
@test BenchmarkProfiles.powertick("15") == "2¹⁵"
@test BenchmarkProfiles.powertick("2.1") == "2²⋅¹"
@test BenchmarkProfiles.powertick("\$15\$") == "\$2^{15}\$"
@test BenchmarkProfiles.powertick("\$2.1\$") == "\$2^{2.1}\$"
@test BenchmarkProfiles.powertick(L"$15$") == L"$2^{15}$"
@test BenchmarkProfiles.powertick(L"$2.1$") == L"$2^{2.1}$"
end
Expand Down

0 comments on commit a6b2e7f

Please sign in to comment.