Skip to content

Commit b06b586

Browse files
committed
new version supporting for chinese
1 parent 1855bc5 commit b06b586

File tree

12 files changed

+109
-15
lines changed

12 files changed

+109
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,4 @@ dmypy.json
115115

116116
.idea/
117117
*.DS_Store
118+
*/temp

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ It is a light and useful Python module, helping you generate a small size, prett
2323
* [Run a `Journalist()` in your code to fetch variables](#run-a--journalist----in-your-code-to-fetch-variables)
2424
* [Invite a journalist to make a big news report](#invite-a-journalist-to-make-a-big-news-report)
2525
- [I am too lazy to write a `md` template](#i-am-too-lazy-to-write-an--md--template)
26+
- [Support For zh_CN](#support-for-zh_cn)
2627
- [What will my variables on slides look like?](#what-will-my-variables-on-slides-look-like-)
2728
- [More examples and instructions](#more-examples-and-instructions)
2829
- [Tips](#tips)
@@ -146,6 +147,31 @@ Output ([raw file](./demo/auto_report.pdf) ):
146147

147148
![](./demo/auto_report.png)
148149

150+
## Support For zh_CN
151+
152+
Yes, now, from version 0.0.5, it can use template contains chinese characters :tada:.
153+
154+
Just pass argument `zh=True` when creating a Journalist(), or set its `zh` property at any time before generating reports.
155+
156+
```py
157+
reporter = Journalist(template_file='./reports/template.md', zh=True)
158+
```
159+
160+
If you want to use your customized template with chinese characters, don't forget to add one line at first of the YAML metadata block in your `Markdown` template:
161+
162+
```markdown
163+
---
164+
documentclass: ctexbeamer
165+
...
166+
---
167+
```
168+
169+
Here is a [simple example](./examples/3_zh_CN_support.py) similar to [Quick start](#quick-start), Except for [its template](./examples/reports/3_zh_cn_template.md) containing chinese characters. A perfect chinese [slides](./examples/reports/3_zh_report.pdf) file can be generated by the program as:
170+
171+
![](./demo/zh_demo.png)
172+
173+
**Note**: make sure `xelatex` is installed properly.
174+
149175
## What will my variables on slides look like?
150176

151177
All variables pass to `Journalist` via `hear` will display as strings just like what their `__str__` method does.

demo/zh_big_news.pdf

40.9 KB
Binary file not shown.

demo/zh_demo.png

99.6 KB
Loading

examples/3_zh_CN_support.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import numpy as np
2+
import pandas as pd
3+
import matplotlib.pyplot as plt
4+
from hkjournalist import Journalist
5+
6+
config = {}
7+
8+
9+
def sin_2x_and_cos_2x(x):
10+
y = np.sin(x) * np.sin(x) + np.cos(x) * np.cos(x)
11+
return y
12+
13+
14+
x = np.arange(0, 4 * np.pi, 0.1)
15+
y1 = np.sin(x)
16+
y2 = np.cos(x)
17+
18+
df = pd.DataFrame({'x': x, 'sin(x)': y1, 'cos(x)': y2})
19+
df['sin^2^(x)+cos^2^(x)'] = sin_2x_and_cos_2x(df['x']).values
20+
df = df.set_index('x')
21+
22+
# plot sine curve as sin_plot
23+
ax = df.plot()
24+
plt.tight_layout()
25+
config['sin_plot'] = ax
26+
27+
# random select 5 point (x,y) as sin_table
28+
config['sin_table'] = df.sample(5)
29+
30+
config['sin_func'] = sin_2x_and_cos_2x
31+
32+
reporter = Journalist(template_file='./reports/3_zh_cn_template.md', zh=True)
33+
reporter.hear(config)
34+
reporter.report(output_file='./reports/3_zh_report.pdf', beamer=True, overwrite=True)

examples/reports/.DS_Store

-6 KB
Binary file not shown.

examples/reports/2_feature_select.pdf

41 Bytes
Binary file not shown.

examples/reports/2_feature_select_template.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
% Report template
2-
% Author
3-
% {today}
4-
1+
---
2+
title: template
3+
author: Author
4+
date: \today{{}}
5+
---
56
### Cover_type
67

78
{Cover_type}

examples/reports/3_zh_cn_template.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
documentclass: ctexbeamer
3+
title: 中文报告
4+
author: 香港记者
5+
date: \today{{}}
6+
---
7+
8+
### 正弦曲线
9+
10+
![]({sin_plot})
11+
12+
### 正弦取值
13+
14+
{sin_table}
15+
16+
### 正弦函数
17+
18+
```{{.python}}
19+
{sin_func}
20+
```
21+
22+

examples/reports/3_zh_report.pdf

34.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)