-
Notifications
You must be signed in to change notification settings - Fork 955
typsium-ghs:0.1.1 #4237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ants-Aare
wants to merge
1
commit into
typst:main
Choose a base branch
from
Typsium:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
typsium-ghs:0.1.1 #4237
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) 2025 | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| [](https://github.com/Typsium/typsium-ghs) | ||
| [](https://github.com/Typsium/typsium/blob/main/LICENSE) | ||
|  | ||
|
|
||
| # Typst GHS and HP Statements | ||
|
|
||
| A Typst package for quickly displaying and formatting Hazard and Precautionary statements. | ||
|
|
||
| ## Usage | ||
| Use the `#ghs` command to display a GHS pictogram, to get more information about each pictogram use `#ghs-info` | ||
| ```typst | ||
| #import "@preview/typsium-ghs:0.1.0": * | ||
| #grid( | ||
| columns: 9, | ||
| ..range(1,10).map(x=> ghs(x)) | ||
| ) | ||
| ``` | ||
|  | ||
|
|
||
| Easily Display Hazard and Precautionary statements in three languages (english, french and german): | ||
| ```typst | ||
| #h-statement(310)\ | ||
| #p-statement(310)\ | ||
| #hp("P305+P351+P338", only-statement:true) | ||
| ``` | ||
|  | ||
|
|
||
| There are variants for some statements: | ||
| ```typst | ||
| #p-statement(310, only-statement: true)\ | ||
| #p-statement(310, variant:1)\ | ||
| #p-statement(310, variant:2) | ||
| ``` | ||
|  | ||
|
|
||
| You can also add parameters when needed: | ||
| ```typst | ||
| #h-statement(370)\ | ||
| #h-statement(370, parameters:"the lungs")\ | ||
| #h-statement(370, parameters:("the lungs", "when inhaled"))\ | ||
| #h-statement(370, variant:1)\ | ||
| #h-statement(370, variant:1, parameters:"when inhaled")\ | ||
| ``` | ||
|  | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #let validate-index(index)={ | ||
| if type(index) == str{ | ||
| return int(index.find(regex("\d+"))) | ||
| }else if type(index) == int{ | ||
| return index | ||
| } | ||
| return 1 | ||
| } | ||
|
|
||
| #let ghs-info=( | ||
| GHS01:(name:"Explosive",image:"resources/ghs-pictograms/GHS01.svg", usage:("Unstable explosives", "Explosives", "Self-reactive substances and mixtures", "Organic peroxides")), | ||
| GHS02:(name:"Flammable",image:"resources/ghs-pictograms/GHS02.svg", usage: ("Flammable gases", "Flammable aerosols", "Flammable liquids", "Flammable solids", "Self-reactive substances and mixtures", "Pyrophoric liquids", "Pyrophoric solids", "Combustible solids", "Combustible liquids", "Self-heating substances and mixtures", "Substances and mixtures, which in contact with water, emit flammable gases", "Organic peroxides")), | ||
| GHS03:(name:"Oxidizing",image:"resources/ghs-pictograms/GHS03.svg", usage:("Oxidizing gases", "Oxidizing liquids", "Oxidizing solids")), | ||
| GHS04:(name:"Compressed Gas",image:"resources/ghs-pictograms/GHS04.svg", usage:("Compressed gases", "Liquefied gases", "Refrigerated liquefied gases", "Dissolved gases")), | ||
| GHS05:(name:"Corrosive",image:"resources/ghs-pictograms/GHS05.svg", usage:("Corrosive to metals", "Skin corrosion", "Serious eye damage")), | ||
| GHS06:(name:"Toxic",image:"resources/ghs-pictograms/GHS06.svg", usage:("Acute toxicity (oral, dermal, inhalation)",)), | ||
| GHS07:(name:"Health Hazard",image:"resources/ghs-pictograms/GHS07.svg", usage:("Acute toxicity (oral, dermal, inhalation)", "Skin irritation", "Eye irritation", "Skin sensitization", "Specific target organ toxicity following single exposure", "Respiratory tract irritation", "Narcotic effects")), | ||
| GHS08:(name:"Serious Health hazard",image:"resources/ghs-pictograms/GHS08.svg", usage:("Respiratory sensitization", "Germ cell mutagenicity", "Carcinogenicity", "Reproductive toxicity", "Specific target organ toxicity following single exposure", "Specific target organ toxicity following repeated exposure", "Aspiration hazard")), | ||
| GHS09:(name:"Toxic",image:"resources/ghs-pictograms/GHS09.svg", usage:("Acute hazards to the aquatic environment", "Chronic hazards to the aquatic environment")), | ||
| ) | ||
|
|
||
| #let ghs( | ||
| icon, | ||
| width:auto, | ||
| height:auto, | ||
| fit: "cover", | ||
| )={ | ||
| let index = calc.clamp(validate-index(icon), 1, 9) | ||
|
|
||
| image("resources/ghs-pictograms/GHS0" + str(index) + ".svg", height: height, width: width, alt: ghs-info.at("GHS0"+ str(index)).name + " sign", fit: fit) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| #let get-language-index(lang)={ | ||
| if lang == "en"{1} | ||
| else if lang == "de"{0} | ||
| else if lang == "fr"{2} | ||
| else if lang == "it"{3} | ||
| else{1} | ||
| } | ||
|
|
||
| #let database = state("hp-statements", csv("resources/hp-statements.tsv", delimiter: "\t", row-type: dictionary)) | ||
|
|
||
| #let validate-string(statement, substitute)={ | ||
| if statement.contains(regex("p|P")){ | ||
| substitute = "P" | ||
| } else if statement.contains(regex("h|H")){ | ||
| substitute = "H" | ||
| } | ||
|
|
||
| statement = statement.replace(regex("[A-Za-z ,-]"), "") | ||
| statement = upper(statement) | ||
|
|
||
| statement = statement.replace(regex("(\d+)"), x=> substitute + x.text) | ||
|
|
||
| return statement | ||
| } | ||
|
|
||
| #let validate-statement(statement, substitute)={ | ||
| if type(statement) == int { | ||
| substitute + str(statement) | ||
| } else if type(statement) == str{ | ||
| validate-string(statement, substitute) | ||
| } else if type(statement) == content{ | ||
| validate-string(statement.text(), substitute) | ||
| } | ||
| } | ||
|
|
||
| #let get-statement(statement, variant, parameters, only-statement, as-hover,default: x=> "no statement found: " + repr(x))={ | ||
| let x = parameters.len() | ||
| let parameterlen = if type(parameters) == str{ | ||
| "-1" | ||
| }else { | ||
| if parameters.len() > 0 {"-"+str(parameters.len())}else{""} | ||
| } | ||
|
|
||
| context { | ||
| let lang-index = get-language-index(text.lang) | ||
| let db = database.get().at(lang-index) | ||
| let full-statement | ||
| if variant != auto{ | ||
| let variant = "."+ str(variant) | ||
| full-statement = db.at(statement + variant + parameterlen, default: db.at(statement + variant, default: db.at(statement, default: none))) | ||
| }else{ | ||
| full-statement = db.at(statement + parameterlen, default: db.at(statement, default: none)) | ||
| } | ||
|
|
||
| if full-statement == none { | ||
| if statement.contains("+"){ | ||
| full-statement = statement.split("+").map(x=> db.at(x, default:"")+ " ").sum() | ||
| } | ||
| } | ||
|
|
||
| if full-statement == none { | ||
| full-statement = default(statement) | ||
| } | ||
|
|
||
| if type(full-statement) == str{ | ||
| if type(parameters) == str{ | ||
| full-statement = full-statement.replace("{1}", parameters) | ||
| } else if type(parameters) == array{ | ||
| full-statement = full-statement.replace("{1}", parameters.at(0, default: "…")) | ||
| .replace("{2}", parameters.at(1, default: "…")) | ||
| } | ||
| } | ||
|
|
||
| if not only-statement{ | ||
| full-statement = statement +": "+ full-statement | ||
| } | ||
|
|
||
| if as-hover{ | ||
| return link(full-statement.replace(" ", "_"), statement) | ||
| } | ||
| return full-statement | ||
| } | ||
| } | ||
|
|
||
| /// | ||
| /// Displays a hazard statement. | ||
| /// - statement (): the code of the statement to display | ||
| /// - variant (): selects which variant to display. only applicable for some statements | ||
| /// - parameters (): additional parameters can manually be added and are filled into the hp-statements based on the order they appear in | ||
| /// - only-statement (bool): should the code of the statement be displayed | ||
| /// - as-hover (bool): Will display statements only as their code, but provides the full statement inside a link so it is shown when hovering over it. May not work in all PDF viewers | ||
| /// - validate (): only change this if you are a plugin developer and know you can skip validation | ||
| /// -> content | ||
| #let h-statement(statement, variant: auto, parameters: (), only-statement:false, as-hover:false, validate: true)={ | ||
| if validate{ | ||
| statement = validate-statement(statement, "H") | ||
| } | ||
|
|
||
| return get-statement(statement, variant, parameters, only-statement, as-hover) | ||
| } | ||
|
|
||
| /// | ||
| /// Displays a precautionary statement. | ||
| /// - statement (): the code of the statement to display | ||
| /// - variant (): selects which variant to display. only applicable for some statements | ||
| /// - parameters (): additional parameters can manually be added and are filled into the hp-statements based on the order they appear in | ||
| /// - only-statement (bool): should the code of the statement be displayed | ||
| /// - as-hover (bool): Will display statements only as their code, but provides the full statement inside a link so it is shown when hovering over it. May not work in all PDF viewers | ||
| /// - validate (): only change this if you are a plugin developer and know you can skip validation | ||
| /// -> content | ||
| #let p-statement(statement, variant: auto, parameters: (), only-statement:false,as-hover:false, validate: true)={ | ||
| if validate{ | ||
| statement = validate-statement(statement, "P") | ||
| } | ||
|
|
||
| return get-statement(statement, variant, parameters, only-statement, as-hover) | ||
| } | ||
| /// | ||
| /// Displays a hazard or precautionary statement. The type is inferred from if the code contains an H or a P. if integers are provided it defaults to precautionary statements | ||
| /// - statement (): the code of the statement to display | ||
| /// - variant (): selects which variant to display. only applicable for some statements | ||
| /// - parameters (): additional parameters can manually be added and are filled into the hp-statements based on the order they appear in | ||
| /// - only-statement (bool): should the code of the statement be displayed | ||
| /// - as-hover (bool): Will display statements only as their code, but provides the full statement inside a link so it is shown when hovering over it. May not work in all PDF viewers | ||
| /// - validate (): only change this if you are a plugin developer and know you can skip validation | ||
| /// -> content | ||
| #let hp(statement, variant: auto, parameters: (), only-statement:false,as-hover:false, validate: true)= p-statement(statement, variant:variant, parameters:parameters, only-statement:only-statement, as-hover: as-hover, validate:validate) | ||
|
|
||
| #let split-statements(statements, validate: true)={ | ||
| statements = if type(statements) == str{ | ||
| statements.split(regex("[,\s\-]+")).filter(x=> x.len() != 0) | ||
| } else if type(statements) == array{ | ||
| statements.map(x=> x.split(regex("[,\s\-]+"))).flatten().filter(x=> x.len() != 0) | ||
| } | ||
| if validate{ | ||
| statements.map(x=> validate-statement(x, "P")) | ||
| }else{ | ||
| statements | ||
| } | ||
| } | ||
|
|
||
| /// | ||
| /// Displays multiple hazard and precautionary statements | ||
| /// - statements (str|array): a list of statement codes to display. | ||
| /// - only-statement (bool): should the code of the statement be displayed | ||
| /// - as-hover (bool): Will display statements only as their code, but provides the full statement inside a link so it is shown when hovering over it. May not work in all PDF viewers | ||
| /// - validate (bool): only change this if you are a plugin developer and know you can skip validation | ||
| /// -> content | ||
| #let display-statements(statements, only-statement:false, as-hover:false, validate: true)={ | ||
| statements = split-statements(statements, validate:validate) | ||
| for value in statements { | ||
| hp(value, only-statement:only-statement,as-hover:as-hover, validate:validate) | ||
| linebreak() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #import "ghs.typ": ghs, ghs-info | ||
| #import "hp.typ": h-statement, p-statement, hp, split-statements, display-statements |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please update the import here?