diff options
author | Norbert Preining <norbert@preining.info> | 2024-12-01 03:03:28 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2024-12-01 03:03:28 +0000 |
commit | 2c8ea3287e3d336f2d0bb0f57f0b1d7bd9221ab6 (patch) | |
tree | acf423731838d4eb2cabe7d7f87eca8c1e3349ad /macros/latex/contrib/jsonparse | |
parent | 73f974c44a227a9988238fa4a325dfb7bba6e3f2 (diff) |
CTAN sync 202412010303
Diffstat (limited to 'macros/latex/contrib/jsonparse')
-rw-r--r-- | macros/latex/contrib/jsonparse/README.md | 2 | ||||
-rw-r--r-- | macros/latex/contrib/jsonparse/jsonparse-doc.pdf | bin | 488017 -> 519126 bytes | |||
-rw-r--r-- | macros/latex/contrib/jsonparse/jsonparse-doc.tex | 34 | ||||
-rw-r--r-- | macros/latex/contrib/jsonparse/jsonparse.sty | 50 |
4 files changed, 66 insertions, 20 deletions
diff --git a/macros/latex/contrib/jsonparse/README.md b/macros/latex/contrib/jsonparse/README.md index 4b4843424e..dc7757b826 100644 --- a/macros/latex/contrib/jsonparse/README.md +++ b/macros/latex/contrib/jsonparse/README.md @@ -1,4 +1,4 @@ - +  diff --git a/macros/latex/contrib/jsonparse/jsonparse-doc.pdf b/macros/latex/contrib/jsonparse/jsonparse-doc.pdf Binary files differindex 703bb870ea..1555c7088a 100644 --- a/macros/latex/contrib/jsonparse/jsonparse-doc.pdf +++ b/macros/latex/contrib/jsonparse/jsonparse-doc.pdf diff --git a/macros/latex/contrib/jsonparse/jsonparse-doc.tex b/macros/latex/contrib/jsonparse/jsonparse-doc.tex index a700978416..897f68cbca 100644 --- a/macros/latex/contrib/jsonparse/jsonparse-doc.tex +++ b/macros/latex/contrib/jsonparse/jsonparse-doc.tex @@ -11,15 +11,15 @@ % This work has the LPPL maintenance status `maintained'. % \documentclass[a4paper]{article} -\def\jsonparsefileversion{0.9.7} -\def\jsonparsefiledate{5 November 2024} +\def\jsonparsefileversion{0.9.8} +\def\jsonparsefiledate{30 November 2024} \usepackage[T1]{fontenc} \usepackage{Alegreya} \usepackage{AlegreyaSans} \usepackage{FiraMono} -\usepackage{geometry, longtable, booktabs, tcolorbox, hyperref} +\usepackage{geometry, longtable, booktabs, siunitx, tcolorbox, hyperref} \geometry{margin=25mm, left=45mm} \usepackage{fancyhdr} @@ -206,6 +206,7 @@ \changes{v0.9.5}{2024/10/27}{Streamlining of code, clarification of explanations in documentation.} \changes{v0.9.6}{2024/10/31}{Allowing for multiple return values when mapping over arrays.} \changes{v0.9.7}{2024/11/05}{Streamlining of code, ensuring backward compatibility.} +\changes{v0.9.8}{2024/11/19}{Bug fixes, adding possibility to store value in token list.} \begin{document} \vspace*{-1cm} @@ -316,7 +317,7 @@ The command \macro{\JSONParseKeys} is used to store all top-level keys of a pars \begin{macrodef} |\JSONParseValue|[<options>]{<token variable>}{<key>} \end{macrodef} -The command \macro{\JSONParseValue} is used to select values from the token variable (property list) that has been created using the commands \macro{\JSONParse} or \macro{\JSONParseFromFile}. The first argument takes the token variable that holds the parsed JSON data. The second argument takes the key to select the relevant entry from the parsed JSON data using JavaScript syntax. +The command \macro{\JSONParseValue} is used to select values from the token variable (property list) that has been created using the commands \macro{\JSONParse} or \macro{\JSONParseFromFile}. The second argument takes the token variable that holds the parsed JSON data. The third argument takes the key to select the relevant entry from the parsed JSON data using JavaScript syntax. If the JSON string \macro{{ "key" : "value" }} is parsed into the token variable \macro{\myJSONdata}, using \macro{\JSONParseValue{\myJSONdata}{key}} would extract the value associated with the key \macro{key}, which in this case is \macro{value}, and typeset it to the document. @@ -336,9 +337,32 @@ Whole objects or arrays can be output as JSON string for further use in other ma For example, if the JSON string \macro{{ "key" : "value" }} has been parsed into the token variable \macro{\myJSONdata}, the command \macro{\JSONParseExpandableValue{\myJSONdata}{key}} will expand to the exact same token list as \macro{\detokenize{value}} with all characters having category code 12 (``other''). \begin{macrodef} +|\JSONParseSetValue|{<token variable>}{<token variable>}{<key>} +\end{macrodef} +The expandable command \macro{\JSONParseValueSet} can be used to a select a value from the token variable that stores the parsed JSON data via a key and store this value in another token variable. + +The first argument denotes the token variable where the value should be stored into. If this token variable has not yet been defined, it will be created by this command. The second argument represents the token variable (property list) that has been created using the commands \macro{\JSONParse} or \macro{\JSONParseFromFile} and that stores the parsed JSON data. The third argument takes the key to select the relevant value. + +The token list returned by this command is a string variable where all characters have category code 12 (``other''), except for spaces and (horizontal) tabs that have category code 10 (``space''). + +\begin{macrodef} +|\JSONParseSetRescanValue|{<token variable>}{<token variable>}{<key>} +\end{macrodef} +The expandable command \macro{\JSONParseSetRescanValue} works the same way and also takes the same arguments as \macro{\JSONParseSetValue} except that it rescans the return value before storing it in the token variable. This means that the value stored in the token list will have the category codes TeX uses per default. + +This can, for example, be necessary when numbers stored in the JSON data in scientific format should be formatted using the \macro{siunitx} package. The rescan is needed here, because otherwise the character \macro{e} would have the wrong category code and would hence not be recognised by the formatting parser as exponent marker. Let us assume the key \macro{number} in some JSON source parsed into the token variable \macro{\myJSONnumber} represents the value \macro{-1.1e-1}, then the following could be used to format the output: + +\JSONParse{\myJSONnumber}{ { "number" : -1.1e-1 } } +\begin{codeexamplecolumns} +\JSONParseSetRescanValue{\mynumber} + {\myJSONnumber}{number} +\num{\mynumber} +\end{codeexamplecolumns} + +\begin{macrodef} |\JSONParseArrayValues|[<options>]{<token variable>}{<key>}[<subkey>]{<string>} \end{macrodef} -The command \macro{\JSONParseArrayValues} is used to select all values from an array from a parsed JSON string or JSON file. The first argument takes the token variable that holds the parsed JSON data. The second argument takes the key to select the relevant entry from the parsed JSON data using JavaScript syntax. The third argument is optional and can be used to pass a subkey, i.\,e. a key that is used to select a value for every item. The last argument takes a string that is inserted between all values when they are typeset. +The command \macro{\JSONParseArrayValues} is used to select all values from an array from a parsed JSON string or JSON file. The second argument takes the token variable that holds the parsed JSON data. The first argument takes the key to select the relevant entry from the parsed JSON data using JavaScript syntax. The third argument is optional and can be used to pass a subkey, i.\,e. a key that is used to select a value for every item. The last argument takes a string that is inserted between all values when they are typeset. For example, let us assume the following JSON data structure is parsed into the token variable \macro{\myJSONdata}: diff --git a/macros/latex/contrib/jsonparse/jsonparse.sty b/macros/latex/contrib/jsonparse/jsonparse.sty index a477d1d35f..a8e21835b4 100644 --- a/macros/latex/contrib/jsonparse/jsonparse.sty +++ b/macros/latex/contrib/jsonparse/jsonparse.sty @@ -10,14 +10,15 @@ % % This work has the LPPL maintenance status `maintained'. % -\ProvidesExplPackage {jsonparse} {2024-11-05} {0.9.7} +\ProvidesExplPackage {jsonparse} {2024-11-30} {0.9.8} {A handy way to parse, store and access JSON data from files or strings in LaTeX documents} \bool_new:N \l__jsonparse_debug_mode_bool + \keys_define:nn { jsonparse / global } { - debug .bool_set:N = \l__jsonparse_debug_mode_bool , - debug .default:n = { true } , - debug .initial:n = { false } + debug .bool_set:N = \l__jsonparse_debug_mode_bool , + debug .default:n = { true } , + debug .initial:n = { false } } \ProcessKeyOptions [ jsonparse / global ] @@ -330,14 +331,21 @@ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } -\clist_const:Ne \c__jsonparse_num_others_clist { +\clist_const:Ne \c__jsonparse_num_plus_minus_fraction_clist { \tl_to_str:n { + } , \tl_to_str:n { - } , - \tl_to_str:n { . } , + \tl_to_str:n { . } +} + +\clist_const:Ne \c__jsonparse_num_exponent_clist { \tl_to_str:n { e } , \tl_to_str:n { E } } +\clist_concat:NNN \c__jsonparse_num_others_clist + \c__jsonparse_num_plus_minus_fraction_clist + \c__jsonparse_num_exponent_clist + \prg_new_conditional:Npnn \jsonparse_if_num:n #1 { p , T , F , TF } { \bool_set_true:N \l__jsonparse_num_bool \bool_set_false:N \l__jsonparse_num_zero_seen_bool @@ -415,7 +423,7 @@ \bool_set_false:N \l__jsonparse_num_bool } } { - \clist_if_in:NVT \c__jsonparse_num_others_clist \l__jsonparse_num_input_last_tl { + \clist_if_in:NVT \c__jsonparse_num_plus_minus_fraction_clist \l__jsonparse_num_input_last_tl { \tl_set:Nn \l__jsonparse_num_remainder_tl { } \bool_set_false:N \l__jsonparse_num_bool } @@ -940,10 +948,6 @@ \group_end: } -\NewExpandableDocumentCommand { \JSONParseExpandableValue } { m m } { - \prop_item:Ne #1 {#2} -} - \cs_set_eq:NN \__jsonparse_tex_quote: \" \cs_set_eq:NN \__jsonparse_tex_backslash: \\ @@ -990,6 +994,24 @@ \group_end: } +\NewExpandableDocumentCommand { \JSONParseExpandableValue } { m m } { + \prop_item:Ne #1 {#2} +} + +\NewExpandableDocumentCommand { \JSONParseSetValue } { m m m } { + \tl_if_exist:NF #1 { + \tl_new:N #1 + } + \tl_set:Nne #1 { \prop_item:Ne #2 {#3} } +} + +\NewExpandableDocumentCommand { \JSONParseSetRescanValue } { m m m } { + \tl_if_exist:NF #1 { + \tl_new:N #1 + } + \tl_set_rescan:Nne #1 { } { \prop_item:Ne #2 {#3} } +} + \NewDocumentCommand { \JSONParseValue } { O{} m m } { \group_begin: \keys_set_known:nn { jsonparse / typeset } {#1} \l__jsonparse_unused_keys_clist @@ -1195,7 +1217,7 @@ \use:c { \l__jsonparse_array_map_function_str } } -\cs_set:Npn \__jsonparse_array_map_create_cs:n #1 { +\cs_set:Npn \__jsonparse_array_map_generate_cs:n #1 { \int_incr:N \l__jsonparse_array_keys_index_int \tl_set:Ne \l__jsonparse_array_keys_index_roman_tl { \int_to_Roman:n { \l__jsonparse_array_keys_index_int } @@ -1220,7 +1242,7 @@ \clist_if_empty:NF \l__jsonparse_array_map_keys_clist { \int_zero:N \l__jsonparse_array_keys_index_int \clist_map_function:NN \l__jsonparse_array_map_keys_clist - \__jsonparse_array_map_create_cs:n + \__jsonparse_array_map_generate_cs:n } #6 \int_step_function:nN { \l__jsonparse_array_count_int } @@ -1229,4 +1251,4 @@ \group_end: } -% EOF +% === |