> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/vi/bai-viet-chuyen-sau/44-step-8-how-to-create-a-simple-latex-package-to-configure-your-variable-fonts.md).

# Bước 8: Cách tạo một gói LaTeX đơn giản để cấu hình phông chữ biến đổi của bạn

&#x20;[Giới thiệu](https://www.overleaf.com/learn/latex/Articles/How_to_use_OpenType_variable_fonts_with_LaTeX?preview=true)   [Bước 1](https://www.overleaf.com/learn/latex/Articles/Step_1:_Setting_up_an_Overleaf_project_to_use_variable_fonts?preview=true)   [Bước 2](https://www.overleaf.com/learn/latex/Articles/Step_2:_An_introduction_to_LaTeX_fonts?preview=true)   [Bước 3](https://www.overleaf.com/learn/latex/Articles/Step_3:_Replacing_LaTeX’s_default_fonts_with_variable_fonts?preview=true)   [Bước 4](https://www.overleaf.com/learn/latex/Articles/Step_4:_How_to_configure_an_italic_variable_font_using_fontspec?preview=true)   [Bước 5](https://www.overleaf.com/learn/latex/Articles/Step_5:_LaTeX_font_weights_and_named_instances_of_variable_fonts?preview=true)   [Bước 6](https://www.overleaf.com/learn/latex/Articles/Step_6:_Using_variable_fonts_to_add_bold_fonts_to_an_Overleaf_project?preview=true)   [Bước 7](https://www.overleaf.com/learn/latex/Articles/Step_7:_Using_Noto_Sans_and_Roboto_Mono_variable_fonts_with_LaTeX?preview=true)   [Bước 8](https://www.overleaf.com/learn/latex/Articles/Step_8:_How_to_create_a_simple_LaTeX_package_to_configure_your_variable_fonts?preview=true)   [Ví dụ và dự án](https://www.overleaf.com/learn/latex/Articles/Overleaf_projects_showing_how_to_use_variable_fonts_with_LaTeX?preview=true)&#x20;

Việc dùng fontspec để cấu hình phông chữ biến thiên có thể làm phần mở đầu của tài liệu trở nên lộn xộn với rất nhiều mã thiết lập. Trong bước này, chúng tôi sẽ chỉ cách tạo một gói đơn giản để chứa mã cấu hình của fontspec—giúp phần mở đầu của tài liệu gọn gàng hơn và dễ thực hiện các thay đổi phông chữ tiếp theo hơn.

## Cách tạo và sử dụng một gói LaTeX đơn giản

Hãy làm theo các bước sau để tạo một gói LaTeX đơn giản cho mã cấu hình fontspec mà chúng ta đã tạo cho hướng dẫn này.

1. Chọn **Tệp mới** biểu tượng (![Overleaf icon representing adding a file](/files/50f5cd78ce6f64a4279f37a5ca9617495f66e1ea)) để tạo một tệp dự án mới. Đặt tên cho nó là `myfontsettings.sty` và chọn **Tạo**.

![Hình ảnh hiển thị cửa sổ hộp thoại Thêm tệp của Overleaf](/files/35730f8765d7685f2ada1e08748c9e16ea01c2fb)

3. Dán mã cấu hình fontspec vào tệp `myfontsettings.sty`. Ở đây, chúng tôi đang dùng mã cấu hình fontspec cho Noto Serif, Noto Sans và Roboto Mono đã được thêm trong hướng dẫn về phông chữ biến thiên. Bạn phải chỉnh sửa các thiết lập fontspec nếu bạn dùng các phông chữ biến thiên khác.

```latex
% myfontsettings.sty
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{myfontsettings}[2024/06/13 v1.0 Thiết lập phông chữ tùy chỉnh của tôi]

% Gói đơn giản này chứa cấu hình fontspec của bạn
% Nó giữ cho phần mở đầu tài liệu của bạn sạch sẽ và gọn gàng

% Tải gói fontspec
\RequirePackage{fontspec}

% Đặt phông chữ văn bản chính cho tài liệu
\setmainfont{NotoSerif-VariableFont-wdth-wght.ttf}[
Weight=400,
ItalicFont=NotoSerif-Italic-VariableFont-wdth-wght.ttf,
FontFace = {b}{n}{Font =NotoSerif-VariableFont-wdth-wght.ttf,Weight=600},
FontFace = {b}{it}{Font =NotoSerif-Italic-VariableFont-wdth-wght.ttf,Weight=600}
]

% Phông chữ sans serif của họ tài liệu
\setsansfont{NotoSans-VariableFont-wdth-wght.ttf}[
Weight=400,
ItalicFont=NotoSans-Italic-VariableFont-wdth-wght.ttf,
FontFace = {b}{n}{Font = NotoSans-VariableFont-wdth-wght.ttf,Weight=600},
FontFace = {b}{it}{Font = NotoSans-Italic-VariableFont-wdth-wght.ttf,Weight=600}
]

% Phông chữ đơn cách của họ tài liệu
\setmonofont{RobotoMono-VariableFont-wght.ttf}[
NFSSFamily=RobotoMono,
Weight=300,
ItalicFont=RobotoMono-Italic-VariableFont-wght.ttf,
FontFace = {b}{n}{Font =RobotoMono-VariableFont-wght.ttf,Weight=550},
FontFace = {b}{it}{Font = RobotoMono-Italic-VariableFont-wght.ttf, Weight=550}
]

\endinput
```

5. Để sử dụng gói này, hãy thêm dòng `\usepackage{myfontsetting}` vào phần mở đầu tài liệu của bạn.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/vi/bai-viet-chuyen-sau/44-step-8-how-to-create-a-simple-latex-package-to-configure-your-variable-fonts.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
