tlienart / Franklin.jl

(yet another) static site generator. Simple, customisable, fast, maths with KaTeX, code evaluation, optional pre-rendering, in Julia.
https://franklinjl.org
MIT License
951 stars 113 forks source link

Bug: Zero argument latex command throwing error #904

Open schlichtanders opened 2 years ago

schlichtanders commented 2 years ago

I just wanted to create my first latex command with zero arguments (like the builtin lx_toc), however I get an error

here my code

function lx_trimurl(com, _)
  trimprefix = locvar(:url_trimprefix)
  urlpath = locvar(:fd_rpath)
  startswith(urlpath, trimprefix) || return ""

  newurlpath = urlpath[length(trimprefix)+1:end]
  md"@def slug = $(repr(newurlpath))"
end

here how I called it within my markdown file

\trimurl

and here the error

ERROR: Franklin.LxObjError("Command/Environment '\\trimurl' expects 1 argument(s) and there\nshould be no space(s) between the command name and the first brace:\n\\com{arg1}... or \\begin{env}{arg1}...\n")
Stacktrace:
  [1] find_opts_braces(τ::Franklin.Token, narg::Int64, braces::Vector{Franklin.OCBlock}, name::SubString{String})
    @ Franklin ~/.julia/packages/Franklin/2KNQE/src/parser/latex/blocks.jl:196
  [2] find_lxcoms(tokens::Vector{Franklin.Token}, lxdefs::Vector{Franklin.LxDef}, braces::Vector{Franklin.OCBlock}, offset::Int64; inmath::Bool)
    @ Franklin ~/.julia/packages/Franklin/2KNQE/src/parser/latex/blocks.jl:291
  [3] find_lxcoms (repeats 2 times)
    @ ~/.julia/packages/Franklin/2KNQE/src/parser/latex/blocks.jl:252 [inlined]
  [4] convert_md(mds::String, pre_lxdefs::Vector{Franklin.LxDef}; isrecursive::Bool, isinternal::Bool, isconfig::Bool, has_mddefs::Bool, pagevar::Bool, nostripp::Bool)
    @ Franklin ~/.julia/packages/Franklin/2KNQE/src/converter/markdown/md.jl:119
  [5] convert_md (repeats 2 times)
    @ ~/.julia/packages/Franklin/2KNQE/src/converter/markdown/md.jl:34 [inlined]
  [6] convert_and_write(root::String, file::String, head::String, pgfoot::String, foot::String, output_path::String)
    @ Franklin ~/.julia/packages/Franklin/2KNQE/src/manager/write_page.jl:175
  [7] process_file_err(case::Symbol, fpair::Pair{String, String}, head::String, pgfoot::String, foot::String, t::Float64)
    @ Franklin ~/.julia/packages/Franklin/2KNQE/src/manager/file_utils.jl:153
  [8] process_file(::Symbol, ::Pair{String, String}, ::String, ::Vararg{Any, N} where N)
    @ Franklin ~/.julia/packages/Franklin/2KNQE/src/manager/file_utils.jl:104
  [9] fd_fullpass(watched_files::NamedTuple{(:other, :infra, :md, :html, :literate), NTuple{5, Dict{Pair{String, String}, Float64}}}, join_to_prepath::String)
    @ Franklin ~/.julia/packages/Franklin/2KNQE/src/manager/franklin.jl:260
 [10] serve(; clear::Bool, verb::Bool, port::Int64, single::Bool, prerender::Bool, nomess::Bool, is_final_pass::Bool, no_fail_prerender::Bool, eval_all::Bool, silent::Bool, cleanup::Bool, on_write::Franklin.var"#236#239", log::Bool, host::String, show_warnings::Bool, fail_on_warning::Bool, launch::Bool, no_set_paths::Bool, join_to_prepath::String)
    @ Franklin ~/.julia/packages/Franklin/2KNQE/src/manager/franklin.jl:124
 [11] serve()
    @ Franklin ~/.julia/packages/Franklin/2KNQE/src/manager/franklin.jl:70
 [12] top-level scope
    @ none:1

what do I need to do to make it work just like \toc works? couldn't find anything in the documentation or the demo extra documentation.

tlienart commented 2 years ago

Apologies for the confusion

So in short for your question: for a lx_* function there is currently no way to just have \somecommand.