{"route":"/en-US-v0.14.1/reference/foundations/content/","title":"Content","description":"Documentation for the Content type.","part":null,"outline":[{"id":"summary","name":"Summary","children":[]},{"id":"example","name":"Example","children":[]},{"id":"representation","name":"Representation","children":[]},{"id":"definitions","name":"Definitions","children":[{"id":"definitions-func","name":"Func","children":[]},{"id":"definitions-has","name":"Has","children":[{"id":"definitions-has-field","name":"field","children":[]}]},{"id":"definitions-at","name":"At","children":[{"id":"definitions-at-field","name":"field","children":[]},{"id":"definitions-at-default","name":"default","children":[]}]},{"id":"definitions-fields","name":"Fields","children":[]},{"id":"definitions-location","name":"Location","children":[]}]}],"body":{"kind":"type","content":{"name":"content","title":"Content","keywords":[],"oneliner":"A piece of document content.","details":"<p>A piece of document content.</p>\n<p>This type is at the heart of Typst. All markup you write and most\n<a href=\"/en-US-v0.14.1/reference/foundations/function/\">functions</a> you call produce content values. You can create a\ncontent value by enclosing markup in square brackets. This is also how you\npass content to functions.</p>\n<h2 id=\"example\">Example</h2>\n<div class=\"previewed-code\"><pre><code>Type of <span class=\"typ-strong\">*Hello!*</span> is\n<span class=\"typ-func\">#</span><span class=\"typ-func\">type</span><span class=\"typ-punct\">(</span><span class=\"typ-punct\">[</span><span class=\"typ-strong\">*Hello!*</span><span class=\"typ-punct\">]</span><span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/5f8a9e925db86201f749a5dfd49d2d6a.png\" alt=\"Preview\"></div></div>\n<p>Content can be added with the <code>+</code> operator,\n<a href=\"/en-US-v0.14.1/reference/scripting/#blocks\">joined together</a> and multiplied with integers. Wherever\ncontent is expected, you can also pass a <a href=\"/en-US-v0.14.1/reference/foundations/str/\">string</a> or <code><span class=\"typ-key\">none</span></code>.</p>\n<h2 id=\"representation\">Representation</h2>\n<p>Content consists of elements with fields. When constructing an element with\nits <em>element function,</em> you provide these fields as arguments and when you\nhave a content value, you can access its fields with <a href=\"/en-US-v0.14.1/reference/scripting/#field-access\">field access\nsyntax</a>.</p>\n<p>Some fields are required: These must be provided when constructing an\nelement and as a consequence, they are always available through field access\non content of that type. Required fields are marked as such in the\ndocumentation.</p>\n<p>Most fields are optional: Like required fields, they can be passed to the\nelement function to configure them for a single element. However, these can\nalso be configured with <a href=\"/en-US-v0.14.1/reference/styling/#set-rules\">set rules</a> to apply them to\nall elements within a scope. Optional fields are only available with field\naccess syntax when they were explicitly passed to the element function, not\nwhen they result from a set rule.</p>\n<p>Each element has a default appearance. However, you can also completely\ncustomize its appearance with a <a href=\"/en-US-v0.14.1/reference/styling/#show-rules\">show rule</a>. The show\nrule is passed the element. It can access the element's field and produce\narbitrary content from it.</p>\n<p>In the web app, you can hover over a content variable to see exactly which\nelements the content is composed of and what fields they have.\nAlternatively, you can inspect the output of the <a href=\"/en-US-v0.14.1/reference/foundations/repr/\" title=\"`repr`\"><code>repr</code></a> function.</p>","constructor":null,"scope":[{"path":["content"],"name":"func","title":"Func","keywords":[],"oneliner":"The content's element function.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>The content's element function. This function can be used to create the element\ncontained in this content. It can be used in set and show rules for the\nelement. Can be compared with global functions to check whether you have\na specific\nkind of element.</p>"}],"self":true,"params":[],"returns":["function"],"scope":[]},{"path":["content"],"name":"has","title":"Has","keywords":[],"oneliner":"Whether the content has the specified field.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Whether the content has the specified field.</p>"}],"self":true,"params":[{"name":"field","details":[{"kind":"html","content":"<p>The field to look for.</p>"}],"types":["str"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["bool"],"scope":[]},{"path":["content"],"name":"at","title":"At","keywords":[],"oneliner":"Access the specified field on the content.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Access the specified field on the content. Returns the default value if\nthe field does not exist or fails with an error if no default value was\nspecified.</p>"}],"self":true,"params":[{"name":"field","details":[{"kind":"html","content":"<p>The field to access.</p>"}],"types":["str"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false},{"name":"default","details":[{"kind":"html","content":"<p>A default value to return if the field does not exist.</p>"}],"types":["any"],"strings":[],"default":null,"positional":false,"named":true,"required":false,"variadic":false,"settable":false}],"returns":["any"],"scope":[]},{"path":["content"],"name":"fields","title":"Fields","keywords":[],"oneliner":"Returns the fields of this content.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Returns the fields of this content.</p>"},{"kind":"example","content":{"body":"<div class=\"previewed-code\"><pre><code><span class=\"typ-func\">#</span><span class=\"typ-func\">rect</span><span class=\"typ-punct\">(</span>\n  width<span class=\"typ-punct\">:</span> <span class=\"typ-num\">10cm</span><span class=\"typ-punct\">,</span>\n  height<span class=\"typ-punct\">:</span> <span class=\"typ-num\">10cm</span><span class=\"typ-punct\">,</span>\n<span class=\"typ-punct\">)</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">fields</span><span class=\"typ-punct\">(</span><span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/ccd95853027f57c192e348066aff8697.png\" alt=\"Preview\"></div></div>","title":null}}],"self":true,"params":[],"returns":["dictionary"],"scope":[]},{"path":["content"],"name":"location","title":"Location","keywords":[],"oneliner":"The location of the content.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>The location of the content. This is only available on content returned\nby <a href=\"/en-US-v0.14.1/reference/introspection/query/\" title=\"query\">query</a> or provided by a <a href=\"/en-US-v0.14.1/reference/styling/#show-rules\">show rule</a>,\nfor other content it will be <code><span class=\"typ-key\">none</span></code>. The resulting location can be\nused with <a href=\"/en-US-v0.14.1/reference/introspection/counter/\">counters</a>, <a href=\"/en-US-v0.14.1/reference/introspection/state/\" title=\"state\">state</a> and <a href=\"/en-US-v0.14.1/reference/introspection/query/\">queries</a>.</p>"}],"self":true,"params":[],"returns":["none","location"],"scope":[]}]}}}