Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ repos:
# E202 whitespace before '}'
# E203 whitespace before ':'
# W503 line break before binary operator
args: ["--ignore=E201,E202,E203,E221,E222,E231,W503"]
args: ["--ignore=E201,E202,E203,E221,E222,E231,E501,W503"]
82 changes: 82 additions & 0 deletions docs/RTL_SUPPORT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# RTL (Right-to-Left) Script Support

The QuantEcon Book Theme now supports RTL (Right-to-Left) scripts including Arabic, Hebrew, Persian, and other RTL languages.

## Usage

To enable RTL support in your Sphinx configuration, add the following to your `conf.py`:

```python
html_theme = "quantecon_book_theme"

html_theme_options = {
"enable_rtl": True, # Enable RTL support
# ... other theme options
}
```

## Configuration

- **Option**: `enable_rtl`
- **Type**: Boolean
- **Default**: `False`
- **Description**: When set to `True`, enables right-to-left text direction and adjusts the entire layout for RTL languages.

## Features

When RTL mode is enabled, the theme automatically adjusts:

### Layout Changes
- **Text Direction**: All text flows from right to left
- **Sidebar Position**: Moves from left to right side
- **Navigation**: Toolbar elements are reversed for RTL flow
- **Margins and Padding**: Adjusted for RTL reading patterns
- **Blockquotes**: Border appears on the right side instead of left

### Preserved Elements
For optimal readability, these elements remain in LTR (Left-to-Right) direction:
- **Code blocks** and syntax highlighting
- **Mathematical equations** and formulas
- **URLs** and technical content

## Example

```python
# conf.py for an Arabic documentation site
project = "دليل البرمجة"
language = "ar" # Arabic language code

html_theme = "quantecon_book_theme"
html_theme_options = {
"enable_rtl": True,
"repository_url": "https://github.com/your-repo/arabic-docs",
# ... other options
}
```

## Supported Languages

This RTL implementation supports all RTL scripts including:
- **Arabic** (العربية)
- **Hebrew** (עברית)
- **Persian/Farsi** (فارسی)
- **Urdu** (اردو)
- **Pashto** (پښتو)
- And other RTL writing systems

## Testing

You can test the RTL functionality by:

1. Setting `enable_rtl = True` in your theme options
2. Building your Sphinx documentation
3. Viewing the generated HTML to see the RTL layout adjustments

The theme includes comprehensive test files demonstrating both LTR and RTL modes side by side.

## Implementation Details

- RTL styles are implemented using CSS `[dir="rtl"]` selectors
- The `dir="rtl"` attribute is conditionally added to the `<body>` element
- Layout adjustments use CSS flexbox and positioning for proper RTL flow
- All changes are backward compatible with existing LTR documents
8 changes: 5 additions & 3 deletions src/quantecon_book_theme/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A lightweight book theme based on the pydata sphinx theme."""

from pathlib import Path
import os
import hashlib
Expand All @@ -12,7 +13,7 @@

from .launch import add_hub_urls

__version__ = "0.8.3"
__version__ = "0.9.0"
"""quantecon-book-theme version"""

SPHINX_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -260,12 +261,13 @@ def get_github_src_folder(app):
context["github_sourcefolder"] = get_github_src_folder(app)

# Make sure the context values are bool
btns = [
blns = [
"theme_use_edit_page_button",
"theme_use_repository_button",
"theme_use_issues_button",
"theme_enable_rtl",
]
for key in btns:
for key in blns:
if key in context:
context[key] = _string_or_bool(context[key])

Expand Down
244 changes: 244 additions & 0 deletions src/quantecon_book_theme/assets/styles/_rtl.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
/*
-----------------------------------
RTL (Right-to-Left) Script Support
-----------------------------------
*/

@use "breakpoints";

// RTL-specific styles for Arabic, Hebrew, Persian, and other RTL languages
[dir="rtl"] {
// Basic text direction
text-align: right;

// Main layout adjustments
.qe-main {
flex-direction: row; // Reverse the row-reverse for RTL
padding-left: 2rem;
padding-right: 2rem;
}

// Page layout
.qe-page {
&__toc {
// Move TOC to the left side for RTL
right: auto;
left: calc(-200px - 3rem);
}

&__header {
&-copy {
flex-direction: row; // Adjust header layout

@media (max-width: breakpoints.$md) {
flex-direction: column;
}
}

&-heading {
margin: 0 0 0 1rem; // Flip margin for RTL

@media (max-width: breakpoints.$md) {
margin: 0;
}
}
}

&__content {
// Adjust text alignment for content
text-align: right;

// Tables should align properly
table {
td, th {
text-align: right;
}

thead {
tr th {
text-align: right !important;
}
}
}

// Code blocks and pre elements maintain LTR for readability
pre, code, .highlight {
direction: ltr;
text-align: left;
}

// Math equations should remain LTR
.math, .MathJax, span.eqno {
direction: ltr;
text-align: left;
}

// Figures and images
.figure {
&.align-left {
text-align: right; // Flip alignment
}
&.align-right {
text-align: left; // Flip alignment
}
}
}
}

// Sidebar adjustments
.qe-sidebar {
// Move sidebar to the right side for RTL
left: auto;
right: 0px;
border-right: none;
border-left: 1px solid #ccc;

&.inactive {
transform: translate3d(100%, 0px, 0px); // Slide to the right when inactive
}

@media (max-width: 1340px) {
box-shadow: -10px 10px 5px 9999px rgba(255, 255, 255, 0.8); // Flip shadow direction
}

&__nav {
ul {
ul {
padding-left: 0;
padding-right: 1rem; // Flip indentation
}
}
}
}

// Toolbar adjustments
.qe-toolbar {
&__inner {
// Reverse toolbar layout
flex-direction: row-reverse;

> ul {
&:first-child {
order: 2; // Move first ul to the right
}

&:last-child {
order: 1; // Move last ul to the left
}
}
}
}

// TOC navigation
.qe-page__toc-nav {
ul {
ul {
padding-left: 0;
padding-right: 1rem; // Flip nested list indentation
}
}
}

// Blockquotes
blockquote {
border-left: none;
border-right: 5px solid #1665ad; // Move border to the right
padding: 0.5rem 2rem 0.5rem 0.5rem; // Adjust padding
}

// Navigation links (prev/next)
.qe-page__toc-footer {
.left-prev {
float: right; // Move to right for RTL
}

.right-next {
float: left; // Move to left for RTL
}
}

// Admonitions
div.admonition,
.admonition {
text-align: right;
}

// Lists
ul, ol {
margin-right: 0;
padding-right: 1.5em;
padding-left: 0;
}

// Definition lists
dl.simple,
dl.field-list {
dd {
margin-left: 0;
margin-right: 1.5em;
}
}

dl.glossary {
dd {
margin-left: 0;
margin-right: 1.5em;
}
}

dl.footnote {
dd {
margin-left: 0;
margin-right: 3em;
}

dd p {
padding-left: 0;
padding-right: 1.5em;
}
}

dl.citation {
margin-left: 0;
margin-right: 3em;
}

// Search functionality
.bd-search {
svg {
right: auto;
left: 2.75rem; // Move search icon to left
}

.search-button__kbd-shortcut {
right: auto;
left: 3em;
}
}

// Cell outputs and inputs
.cell {
.output .prompt,
.input .prompt {
left: auto;
right: -55px; // Move prompts to the right
}
}

// Settings modal adjustments
#settingsModal {
.modal-servers {
li {
i {
margin: 0 1rem 0 0; // Flip margin for icons
}
}
}
}

// Anchor links
.anchor-link, .headerlink {
margin-left: 0;
margin-right: 6px; // Move anchor links to the right
}
}
1 change: 1 addition & 0 deletions src/quantecon_book_theme/assets/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ IMPORTS
@forward "syntax";
@forward "tippy-themes";
@forward "margin";
@forward "rtl";

@import url("https://fonts.googleapis.com/css2?family=PT+Serif:ital,wght@0,700;1,400&family=Source+Sans+Pro:ital,wght@0,400;0,700;1,400;1,700&display=swap");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
{% block sidebarsourcelink %}{% endblock %}

{% block body_tag %}
<body{% if master_doc == pagename %} class="main-index"{% endif %}>
<body{% if master_doc == pagename %} class="main-index"{% endif %}{% if theme_enable_rtl %} dir="rtl"{% endif %}>
{%- endblock %}
{%- block content %}

Expand Down
Loading
Loading