I created/copied this piece of latex preamble code:

    \def\@lessonabbr{Les #1}
        \def\@lesson{Lesson #1}
        \def\@fullLesson{\hfill \small{#2}\hr \@lesson \hfill \small{#4} \\}
    \def\@lessonabbr{Les #1: #3}
        \def\@lesson{Lesson #1: #3}
        \def\@fullLesson{\hfill \small{#2}\hr \@lesson \hfill \small{#4} \\}

\lesson{1}{Mar 18 2022 Fri (16:40:24)}{Write an inequality from Graph}{Unit 2}

How would I make it automatically create a label for me by replacing the spaces with _ and making it all lowercased? I want to use the title of the lesson along with the lesson number. For this case, the label would look like this: les1:write_an_inequality_from_graph_unit_2

Any help will be greatly appreciated!


1 Answer 1

function makeLabel(n,date,title,unit)
 tex.print("les" .. n ..":" .. string.lower(title:gsub("%s+", "\\_")) 
             .. "\\_" .. string.lower(unit:gsub("%s+", "\\_")))


\makeLabel{"1"}{"Mar 18 2022 Fri (16:40:24)"}{"Write an inequality from Graph"}{"Unit 2"}


Compiled using lualatex gives

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.