reox8627 downloadsRender SMILES and SMARTS code blocks as chemical structures, with a button to flip each one between the structures and their source.
Draw chemical structures in your notes from SMILES
strings. Write a smiles code block and the molecule appears in its place, in Reading view and
Live Preview, on desktop and mobile. SMARTS patterns work too.
```smiles
CC(=O)Oc1ccccc1C(=O)O aspirin
```
To install by hand instead, download main.js, manifest.json and styles.css from the
latest release into
<your vault>/.obsidian/plugins/smiles-structure-preview/, then enable the plugin.
Put a SMILES string in a code block tagged smiles. Blocks tagged smi are left as plain code.
Write one molecule per line. Text after the first space is the molecule's label, as in .smi
files. The molecules sit side by side and wrap to the width of the note:
```smiles
CCO ethanol
c1ccccc1 benzene
[Na+].[Cl-] table salt
```
Tag a block smarts to draw substructure patterns instead of molecules. Each constraint is marked
on the atom or bond it applies to:
```smarts
[CX3](=O)[OX2H1] carboxylic acid
[C,N;!H0]~* C or N with a hydrogen
```
A SMARTS pattern in a smiles block is an error: the tag decides how each line is read.
Add options in braces after the tag:
```smiles {caption="Figure 1: Acetylsalicylic acid" align="center" alt="Aspirin"}
CC(=O)Oc1ccccc1C(=O)O
```
| Option | What it does |
|---|---|
caption |
Text shown under the structures. |
align |
left, center or right. |
alt |
A description read aloud by screen readers. |
class |
A CSS class, for styling the structures with a CSS snippet. |
Put each value in quotes. Values are plain text, not Markdown. If an option is misspelled, it's ignored and the structures still appear.
Structures follow your theme. In a dark theme, bonds take your theme's text colour and atom colours are lightened only as much as needed to read, so oxygen stays red and chlorine green. In a light theme, structures appear on a white card with their usual colours.
To always show the usual colours on a white card, turn off Follow dark themes in the plugin's settings.
| Setting | What it does |
|---|---|
| Depiction timeout | How long drawing one molecule may take before it's shown as an error. 3 seconds by default, from 0.5 to 60. |
| Follow dark themes | On by default. Turn off to keep every structure on a white card. |
| Debug logging | Writes ignored options to the developer console, to help find a typo. |
| Command | What it does |
|---|---|
| Show every structure in this note | Switches every block in the note back from strings to structures. |
| Restart renderer | Starts the drawing engine afresh, retrying molecules that timed out. |
Structures are drawn on your device, inside Obsidian. The plugin doesn't connect to the internet, doesn't collect any data, and doesn't read or write any files.
Structures are drawn by OpenChemLib. The licenses of the software built into this plugin are listed in THIRD_PARTY_NOTICES.md.
Released under the MIT License. To build or change the plugin, see DEVELOPMENT.md.