Skip to content

Commit c78f65d

Browse files
committed
use font directories in cli, update docs
1 parent 3a0ec15 commit c78f65d

File tree

17 files changed

+551
-490
lines changed

17 files changed

+551
-490
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/configuration.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Configuration
2+
3+
## Configuration Directory
4+
5+
TyX's configuration directory follows [Tauri's app configuration directory](https://v2.tauri.app/reference/javascript/api/namespacepath/#appconfigdir).
6+
7+
This resolves to the following directories:
8+
9+
- Linux: `$XDG_CONFIG_HOME/com.tyx-editor.tyx` or `$HOME/.config/com.tyx-editor.tyx`
10+
- macOS: `$HOME/Library/Application Support/com.tyx-editor.tyx`
11+
- Windows: `{FOLDERID_RoamingAppData}\com.tyx-editor.tyx`
12+
13+
## Settings
14+
15+
The settings file is called `settings.json` and it follows the [TyX settings schema](https://tyx-editor.com/schemas/tyx-settings.schema.json).
16+
17+
It can be edited in the UI by pressing the default `mod+;` keyboard shortcut or opening settings in the splash screen.
18+
19+
This includes the UI language, your keyboard shortcuts, your math inline shortcuts, and optionally your keyboard map.
20+
21+
!!! tip
22+
23+
You can also create this settings file and then TyX will automatically read and use it!
24+
25+
## Fonts
26+
27+
You can place fonts for use in your TyX documents in a `fonts` directory inside your TyX configuration directory.
28+
29+
TyX automatically adds this to the font paths for documents you compile with it.
30+
31+
## Templates
32+
33+
You can place templates for your TyX documents in a `templates` directory inside your TyX configuration directory.
34+
35+
TyX automatically suggests files from this directory when pressing the "New From Template" option in the splash screen or pressing its default `mod+shift+n` shortcut.

docs/document-settings.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

docs/file-format.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

docs/getting-started.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,12 @@
55
To install TyX, you can go to [tyx-editor.com](https://tyx-editor.com).
66

77
Alternatively, you can download the installer for your operating system from the [GitHub releases](https://github.com/tyx-editor/TyX/releases).
8+
9+
## Using TyX
10+
11+
TyX is intended for two types of users:
12+
13+
- Users who simply wish to easily edit documents and have them look good, without diving too deep.
14+
- Power users who hack TyX and create nice configurations (for their language, institution, etc.).
15+
16+
For power users, it is recommended to read the [Configuration](./configuration.md) section for the various ways to create setups for TyX.

docs/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ It is designed to create an easy-to-use, WYSIWYM interface inspired by LyX.
1111
Keep this in mind!
1212
**Contributions are encouraged and welcomed!**
1313

14+
For installation and more details using TyX, see the [Getting Started](./getting-started.md) section!
15+
1416
## Features
1517

1618
### Math Editor

docs/settings.md

Lines changed: 0 additions & 16 deletions
This file was deleted.

mkdocs.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ markdown_extensions:
2323
nav:
2424
- Introduction:
2525
- getting-started.md
26-
- settings.md
27-
- document-settings.md
26+
- configuration.md
2827
- API Docs:
29-
- file-format.md
3028
- commands.md
3129
- CHANGELOG.md

src-tauri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ typst-pdf.workspace = true
3131
tyx-schema.workspace = true
3232
tyx-converters.workspace = true
3333
tyx-version.workspace = true
34+
directories = "6.0.0"
3435
typstyle-core = "0.13.14"
3536
url = "2.5.4"
3637
open = "5"

src-tauri/src/cli.rs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
use std::path::{Path, PathBuf};
2+
3+
use crate::pdf::typst_to_pdf;
4+
use clap::{Parser, ValueEnum};
5+
6+
#[derive(Debug, Clone, ValueEnum)]
7+
pub(crate) enum ExportFormat {
8+
Typst,
9+
Pdf,
10+
}
11+
12+
impl ExportFormat {
13+
pub(crate) fn extension(&self) -> &str {
14+
match self {
15+
Self::Pdf => ".pdf",
16+
Self::Typst => ".typ",
17+
}
18+
}
19+
20+
pub(crate) fn export(&self, input: String, filename: &str) -> Vec<u8> {
21+
let dirname = Path::new(filename).parent().unwrap().to_str().unwrap();
22+
23+
match self {
24+
Self::Typst => tyx_converters::serialized_tyx_to_typst(&input).into_bytes(),
25+
Self::Pdf => {
26+
let contents = tyx_converters::serialized_tyx_to_typst(&input);
27+
typst_to_pdf(filename, &contents, PathBuf::from(dirname), vec![]).unwrap()
28+
}
29+
}
30+
}
31+
}
32+
33+
/// Simple program to greet a person
34+
#[derive(Parser, Debug)]
35+
#[command(version = tyx_version::VERSION, about, long_about = None, display_name="TyX")]
36+
pub(crate) struct Args {
37+
/// Files to open or export.
38+
pub(crate) files: Vec<String>,
39+
/// Export as this file format, the default output filenames are just replacing the file extension
40+
#[arg(short, long)]
41+
pub(crate) export: Option<ExportFormat>,
42+
/// Save the output to this filename, requires files to be only one.
43+
#[arg(short, long)]
44+
pub(crate) output: Option<String>,
45+
}
46+
47+
impl Args {
48+
pub(crate) fn process(&self) -> bool {
49+
let mut should_exit = false;
50+
51+
let output_filename = match &self.output {
52+
Some(output) => {
53+
assert!(self.files.len() == 1);
54+
Some(output)
55+
}
56+
None => None,
57+
};
58+
for file in self.files.iter() {
59+
let contents = std::fs::read_to_string(file).unwrap();
60+
if let Some(ref format) = self.export {
61+
let file_base = match file.strip_suffix(".tyx") {
62+
Some(file) => file,
63+
None => {
64+
println!("warning: file {file} might not be a TyX document!");
65+
file
66+
}
67+
};
68+
should_exit = true;
69+
let default_filename = String::from(file_base) + format.extension();
70+
let final_output_filename = output_filename.unwrap_or(&default_filename);
71+
println!("Exported to {final_output_filename}");
72+
std::fs::write(final_output_filename, format.export(contents, file)).unwrap();
73+
}
74+
}
75+
76+
should_exit
77+
}
78+
}

0 commit comments

Comments
 (0)