{"record":{"id":"641e9f4239adbaf0","repo":"typst/typst","slug":"cyan-component","errorCode":null,"errorMessage":"cyan component","messagePattern":"cyan component","errorType":"validation","errorClass":"SourceDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/typst-library/src/visualize/color.rs","lineNumber":673,"sourceCode":"        #[external]\n        magenta: RatioComponent,\n        /// The yellow component.\n        #[external]\n        yellow: RatioComponent,\n        /// The key component.\n        #[external]\n        key: RatioComponent,\n        /// Alternatively: The color to convert to CMYK.\n        ///\n        /// If this is given, the individual components should not be given.\n        #[external]\n        color: Color,\n    ) -> SourceResult<Color> {\n        Ok(Self::Process(ProcessColor::Cmyk(\n            if let Some(color) = args.find::<Color>()? {\n                color.to_cmyk()\n            } else {\n                let RatioComponent(c) = args.expect(\"cyan component\")?;\n                let RatioComponent(m) = args.expect(\"magenta component\")?;\n                let RatioComponent(y) = args.expect(\"yellow component\")?;\n                let RatioComponent(k) = args.expect(\"key/black component\")?;\n                Cmyk::new(c.get() as f32, m.get() as f32, y.get() as f32, k.get() as f32)\n            },\n        )))\n    }\n\n    /// Create an HSL color.\n    ///\n    /// This color space is useful for specifying colors by hue, saturation and\n    /// lightness. It is also useful for color manipulation, such as saturating\n    /// while keeping perceived hue.\n    ///\n    /// An HSL color is represented internally by an array of four components:\n    /// - hue (@angle)\n    /// - saturation (@ratio)\n    /// - lightness (@ratio)","sourceCodeStart":655,"sourceCodeEnd":691,"githubUrl":"https://github.com/typst/typst/blob/a51e028041cac426f97d34335bb01d8f1d8e5e8f/crates/typst-library/src/visualize/color.rs#L655-L691","documentation":"Typst's cmyk() constructor (crates/typst-library/src/visualize/color.rs:673) requires exactly four ratio components: cyan, magenta, yellow, key/black. The 'cyan component' error comes from args.expect(\"cyan component\") and is raised when the first positional argument is missing or cannot be cast to a ratio component. Unlike rgb(), cmyk() has no hex-string overload; its only alternative form is passing an existing color to convert, e.g. #cmyk(red).","triggerScenarios":"Calling #cmyk() with no arguments; calling #cmyk(\"#ff0000\") (cmyk does not parse hex strings, so the string is neither a Color nor a RatioComponent and the first expect fails); passing a first argument of the wrong type such as #cmyk(0.3, ...) with a plain float instead of a ratio like 30%.","commonSituations":"Assuming cmyk() accepts hex strings like rgb() does; porting print-shop color specs where values are written as decimals (0.27) instead of Typst ratios (27%); calling cmyk() with keyword arguments only, since components are positional and keywords do not satisfy args.expect.","solutions":["Pass all four components as ratios: #cmyk(27%, 0%, 3%, 5%).","To convert an existing color, pass it as the single argument: #cmyk(rgb(\"#ff0000\")).","If your values are floats, convert them to ratios first: #cmyk(27% or (c * 100)% for components, ...) or multiply by 1% style helpers.","Do not pass a hex string to cmyk(); use #cmyk(rgb(\"#...\")) to go through RGB conversion."],"exampleFix":"// before\n#square(fill: cmyk(\"#ff0000\"))\n\n// after\n#square(fill: cmyk(0%, 100%, 100%, 0%))\n// or convert from an RGB/hex color:\n#square(fill: cmyk(rgb(\"#ff0000\")))","handlingStrategy":"validation","validationCode":"#let safe-cmyk(vals) = {\n  if vals.len() == 4 and vals.all(v => type(v) == ratio) {\n    cmyk(..vals)\n  } else if vals.len() == 1 and type(vals.first()) == color {\n    cmyk(vals.first())\n  } else {\n    luma(0)\n  }\n}","typeGuard":"#let cmyk-input-valid(vals) = (vals.len() == 4 and vals.all(v => type(v) == ratio)) or (vals.len() == 1 and type(vals.first()) == color)","tryCatchPattern":null,"preventionTips":["Remember cmyk() accepts no hex strings; convert via #cmyk(rgb(\"#...\")) instead.","Write CMYK values with explicit % signs - plain floats do not cast to ratio components.","All four components are mandatory; there is no default like rgb()'s alpha."],"tags":["typst","color","cmyk","missing-argument","compile-error"],"backgroundTag":null,"analyzedSha":"a51e028041cac426f97d34335bb01d8f1d8e5e8f","analyzedAt":"2026-08-16T08:13:58.503Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}