1

I created/copied this piece of latex preamble code:

\makeatletter
\def\@lesson{}
\def\@lessonabbr{}
\newcommand{\lesson}[4]{
    \ifthenelse{\isempty{#3}}{
    \def\@lessonabbr{Les #1}
        \def\@lesson{Lesson #1}
        \def\@fullLesson{\hfill \small{#2}\hr \@lesson \hfill \small{#4} \\}
        \subsection[\@lessonabbr]{\@fullLesson}
    \label{\@lesson}
    }{
    \def\@lessonabbr{Les #1: #3}
        \def\@lesson{Lesson #1: #3}
        \def\@fullLesson{\hfill \small{#2}\hr \@lesson \hfill \small{#4} \\}
        \subsection[\@lessonabbr]{\@fullLesson}
    \label{\@lesson}
    }
}
\makeatother

\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!

4

1 Answer 1

1
\documentclass[]{article}
\usepackage{luacode}
\begin{luacode*}
function makeLabel(n,date,title,unit)
 tex.print("les" .. n ..":" .. string.lower(title:gsub("%s+", "\\_")) 
             .. "\\_" .. string.lower(unit:gsub("%s+", "\\_")))
end 
\end{luacode*} 

\newcommand{\makeLabel}[4]{\directlua{makeLabel(#1,#2,#3,#4)}}%

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

\end{document}

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.