#Use Variable Defined in Main Document in the Template

22 messages · Page 1 of 1 (latest)

idle yarrow
#

Is there a way to use a variable that is defined in the main document in a template imported into that document?

When I try to do this, I get the error "unknown variable"

Basically, I have a footer that will change from document to document that I therefore need defined in the main document. The structure of the footer itself is a bit complex and rather ugly, so it is of course in the template.

I simply want to inject the content into the template under the page/footer section.

orchid atlas
#

please send your current template and how you are importing it within your main document

idle yarrow
orchid atlas
#

can you paste them here if possible?

#

it appears they have less than 2k chars so each can be a message

idle yarrow
#

Template

#

It told me no on the template... here's the relevant part though

#

let ltemplate(doc) = [
#set text(
font: "Times New Roman",
style: "normal",
size: 12pt,
)

#set page(
paper: "us-letter",
margin: (left: 1in, right: 1in, top: 1in, bottom: 1in),
footer-descent: 5%,
footer: locate(
loc => if [#loc.page()] == [1] {
[
#align(
center,
line(
start: (0pt, 0pt),
length: (368pt),
stroke: (.5pt + black),

)

)
#v(6pt, weak: true)
==== heading
==== heading
==== heading
} else {
[
#set align(center)
#set text(
font: "Times New Roman",
style: "normal",
size: 10pt)
#counter(page).display(
"-1-"
)
#v(6pt, weak: true)
#line(
start: (0pt, 0pt),
length: (368pt),
stroke: (.5pt + black),

)
#v(6pt, weak: true)
[I want the variable text here]]

    }    
)    

)

orchid atlas
#

right

#

now the main file

idle yarrow
#

#import "disctemplate.typ": ltemplate
#show: ltemplate
//MAIL//
#text(weight: "bold")[Mail Type]
//MAIL//

//DATE//
#align(right)[date]
//DATE//

name
street
address

#text(weight: "bold")[
#str("RE: ")
]


body of letter

orchid atlas
#

ok

#

where will you be setting the footer

#

at the second line of the main file?

idle yarrow
#

Yes.

orchid atlas
#

ok

#
#let ltemplate(doc, footer: []) {
   set page(
      // ... at the  "I want the text here" part
      [#footer]
      // ...
   )
   doc
}
#

and then

#
#show: doc => ltemplate(doc, footer: [stuff])
#

which is equivalent to

#
#show: ltemplate.with(footer: [stuff])
idle yarrow
#

Worked. Thank you! ❤️