Comments (2)
I am considering to support passing arbitrary content for set document(title: ..)
. I also plan to give the templates a facelift fairly soon, so if that didn't happen until then, I'm open to the workaround.
from templates.
@laurmaedje, I have a solution to this problem (which is also mentioned here): To use a string or content for the title of a document, the only problem is to set the title metadata properly, which has to be of type string.
I wrote a function named extractText
that concatenates all strings to be found in a value of type content, string or otherwise and return it. Given the function extractText
the above mentioned line of code in template.typ
can be written as
set document(title: extractText(title), author: authors.map(author => author.name))
The helper function can be outsourced and imported or included in the template:
#let extractText(element) = {
if type(element) == content {
if element == [ ] { return " " }
return extractText(element.fields()).trim() }
if type(element) == dictionary { return extractText(element.values()) }
if type(element) == array {
return element.fold("", (res, item) => res + extractText(item))
}
if type(element) == bool { return "" }
return str(element)
}
#assert.eq(extractText("hey"), "hey")
#assert.eq(extractText(12), "12")
#assert.eq(extractText(12.0), "12")
#assert.eq(extractText(12.1), "12.1")
#assert.eq(extractText(false), "")
#assert.eq(extractText(version(1,2,3)), "1.2.3")
#assert.eq(extractText((1,2,3)), "123")
#assert.eq(extractText((4,(1,"Hey",12.0),(hey: 2))), "41Hey122")
#assert.eq(extractText([This is some text.]), "This is some text.")
#assert.eq(extractText([This is _some_ text.]), "This is some text.")
#assert.eq(extractText([ Is $x^2$ an _even_ Function? ]), "Is x2 an even Function?")
#assert.eq(extractText([Is $x^2$ an _even_ Function?]), "Is x2 an even Function?")
#assert.eq(extractText([[Hey] [you]]), "[Hey] [you]")
What do you think?
from templates.
Related Issues (20)
- ams template: references to theorem labels don't include the heading HOT 2
- Springer Template
- Box artifact appears in AMS template under Typst 0.6 HOT 2
- AMS template doesn't respect figure placement
- AMS table's caption issue HOT 1
- Greater use of Constants HOT 1
- error: expected string or none, found content HOT 1
- Mis-indented first outline entry in the default IEEE template HOT 1
- AMS: springer-mathphys as bibliography style
- AMS proof square drawn over text HOT 1
- How do you develop themes? HOT 3
- ieee template: accept conference instead of paper-size?
- wonderous-book: Two levels of headers HOT 1
- ACL Conferences Template HOT 5
- AMS: Font sizes not whole numbers when they probably should be?
- AMS: Template does not allow author to customize page margins
- IEEE: Wrong indent after equation without following text. HOT 1
- Appendix after references section HOT 4
- Independent counters for `image` and `raw`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from templates.