From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from cgl.ntg.nl (Cgl.ntg.nl [5.39.185.202]) by inbox.vuxu.org (Postfix) with ESMTP id CAF1A21567 for ; Mon, 10 Jun 2024 07:11:12 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by cgl.ntg.nl (Postfix) with ESMTP id 55F4D4835A2 for ; Mon, 10 Jun 2024 07:09:56 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at cgl.ntg.nl Authentication-Results: cgl.ntg.nl (amavisd-new); dkim=fail (2048-bit key) reason="fail (message has been altered)" header.d=telus.net Received: from cgl.ntg.nl ([127.0.0.1]) by localhost (cgl.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WskDuvM1Oln4 for ; Mon, 10 Jun 2024 07:09:55 +0200 (CEST) Received: from cgl.ntg.nl (localhost [127.0.0.1]) by cgl.ntg.nl (Postfix) with ESMTP id 48DFD483B0E for ; Mon, 10 Jun 2024 07:09:07 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by cgl.ntg.nl (Postfix) with ESMTP id 74DBC484B62 for ; Mon, 10 Jun 2024 07:08:32 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at cgl.ntg.nl Received: from cgl.ntg.nl ([127.0.0.1]) by localhost (cgl.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rVI3RC668rQU for ; Mon, 10 Jun 2024 07:08:31 +0200 (CEST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.216.41; helo=mail-pj1-f41.google.com; envelope-from=mseven@telus.net; receiver= Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cgl.ntg.nl (Postfix) with ESMTPS id DC670484B5E for ; Mon, 10 Jun 2024 07:08:31 +0200 (CEST) Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2c1a4192d55so3131623a91.2 for ; Sun, 09 Jun 2024 22:08:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telus.net; s=google; t=1717996109; x=1718600909; darn=ntg.nl; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=T1sYoSm7KFHAXENfbkuw9j5oRVKV2bwsQdGJRJA6Too=; b=f4zSvR4+9jI9eZ4lQK8ayIa3A9estQOV/gidTfbMsHqCmb9274Kc90XeHuYxnzmog8 z/9hdsWOYXqxzsnTE7UMZVyJus8TwS9qAQ3PLi+lgeIJ5o63RuQMsEPDWwbVgL3K4++1 bLzkvfB2vHp5kEOx3A8J67qAMMX7fMvl8qq1E6SfP99Cg866H/tM6H5fwYctZIMUmu/B A+fk2cC/oPXowS43kLBCUR/BXAO5Zuu9bXne42ZwONBMHipCB+mWOHExsb6wC/KfOm9X DNPhSNb7Qc9Isiy6TGfty0CgMO9IVfyB6PLpGzF2nw012PmuLdf6ACjG9wTfKSHytJ8x qqow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717996109; x=1718600909; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=T1sYoSm7KFHAXENfbkuw9j5oRVKV2bwsQdGJRJA6Too=; b=RvyVXNvQI7KEFlD3ZQvAdtuQ7ksT1v8ZWO0KYS2yZnLf2lT4b+y0VNQJbvBodaLR7r n35ypNnIKqLaAlvJdtiZlnsnqqPi4wCIFUtIbMPQtjHp7jVcGEBlnhktelBVDwp/RmqU ZngT1hnf+HueWChBbNFB8M70Form4pArLaDJCTWNoB2ORh/ugHGLXif9IindCrdW5psT eG4a6+foVwaySCY3BGIOtBrBZ1b4ZaPHGmrSCjFNPJENaHT1zZv0RLt2Q02REp9OQxrv oQJ1zDvgqF/Zaj+m36BPeuMVySMG6r3CbwbF+mmeQ0uzzNHjPIy/qahWVu92v3eFU79l I32g== X-Forwarded-Encrypted: i=1; AJvYcCXaKXj04Ss6xa4KPXkg8MQwL7p1lDUPdWWYHYyzaIQLu7zjNcKTaubAbp9IlmNcaKZupiBfCDeDJl4sA9at4cr5ank= X-Gm-Message-State: AOJu0YzvWOXQ+GsOGLD1umw1sEQtMuRAhhWkdkwi7FpieFA2w425OQ+I yijD+kBGf4a20qPn4PN+R70sRQV9bG19029Mve8accFwbnTjlSrvIv6csd8FIqo= X-Google-Smtp-Source: AGHT+IHgqFA5+4KoqCXcMzdwi+Jw5XBcmBUYanDX86A+SF/boUCjamEcJB1UflP9DeZIyp7MsMi7fQ== X-Received: by 2002:a17:90a:990b:b0:2bd:d2f9:fa18 with SMTP id 98e67ed59e1d1-2c2bcc7883cmr7495867a91.48.1717996109236; Sun, 09 Jun 2024 22:08:29 -0700 (PDT) Received: from max-new-laptop.lan ([2604:3d08:e97f:edfd::834]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c301477f3bsm1756598a91.43.2024.06.09.22.08.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 22:08:28 -0700 (PDT) Message-ID: From: Max Chernoff To: Henning Hraban Ramm , ntg-context@ntg.nl Date: Sun, 09 Jun 2024 23:08:27 -0600 In-Reply-To: References: User-Agent: Evolution 3.52.2 (3.52.2-1.fc40) MIME-Version: 1.0 Message-ID-Hash: 6FL5RFVTBEH5GKLO53XOQYVRESUPVNCW X-Message-ID-Hash: 6FL5RFVTBEH5GKLO53XOQYVRESUPVNCW X-MailFrom: mseven@telus.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list Reply-To: mailing list for ConTeXt users Subject: [NTG-context] Re: get measures as dimension in Lua List-Id: mailing list for ConTeXt users Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hi Hraban, On Sun, 2024-06-09 at 22:12 +0200, Henning Hraban Ramm wrote: > when I define a measure on the TeX side, I used to get at the value in > Lua with tex.getdim, like: > > \definemeasure[Bleed][3mm] > > tex.getdimen("Bleed") > > But now I get "incorrect dimen name". > I need it as a dimension, since I do calculations with other dimensions > like "topspace". > > How should I do this correctly? There doesn't appear to be any official interfaces to get the value of a measure from Lua, but the following should work okay: \definemeasure[mymeasure][10pt] \newdimen\mydimen \mydimen=10pt \definemeasure[measureexpr][1in + 27.73pt] \startluacode -- Returns the unexpanded value of some variable in a namespace. local function get_variable(namespace, variable) -- -- Doesn't work since "measure" is defined as a "system namespace". -- namespace = interfaces.getnamespace(namespace) namespace = tokens.getters.macro("??" .. namespace) return tokens.getters.macro(namespace .. variable) end -- Gets the value of a measure and converts it to an integer in sp units. local function get_measure(name) return tex.sp(get_variable("measure", name)) end -- Gets the \dimexpr-evaluated value of a measure, in sp units. local function get_measure_expr(name) local namespace = tokens.getters.macro("??measure") -- Undocumented, but seems to work as expected. return tex.getdimensionvalue(namespace .. name) end -- Print the values of the lengths. print(("="):rep(80)) print("mymeasure:" , get_measure("mymeasure") ) print("mydimen:" , tex.dimen["mydimen"] ) print("measureexpr:", get_measure_expr("measureexpr")) print(("="):rep(80)) \stopluacode \startTEXpage \measure{mymeasure} \the\mydimen \measure{measureexpr} \stopTEXpage Thanks, -- Max ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror) archive : https://github.com/contextgarden/context wiki : https://wiki.contextgarden.net ___________________________________________________________________________________