#775: The BiDi Battle: Fixing Mixed RTL and LTR Text Chaos

Stop fighting your cursor! Discover why mixing RTL and LTR languages breaks your layout and how to fix it using Unicode and CSS.

0:000:00
Episode Details
Published
Duration
27:41
Audio
Direct link
Pipeline
V4
TTS Engine
LLM

AI-Generated Content: This podcast is created using AI personas. Please verify any important information independently.

Managing text that flows in two different directions is a persistent challenge in modern computing. For those working with a mix of Right-to-Left (RTL) languages like Hebrew or Arabic and Left-to-Right (LTR) languages like English, the experience is often defined by "jumping" periods, inverted parentheses, and erratic cursor behavior. These issues stem from the complex way software interprets and displays bidirectional (BiDi) text.

The Unicode Bidirectional Algorithm

At the heart of this issue is the Unicode Bidirectional Algorithm. Computers store text in "logical order"—the sequence in which characters are typed—but must display them in "visual order." The algorithm acts as the translator between these two states. While most letters have a "strong" inherent direction, neutral characters like spaces, numbers, and punctuation marks do not. These characters are designed to take on the direction of the surrounding text. Problems arise when the computer guesses the intended direction incorrectly, such as placing a period at the end of an English word within a Hebrew sentence, causing the mark to appear in the middle of the line rather than at the far left.

Why Email and Apps Fail

Email clients are particularly prone to formatting failures because they lack consistent rendering engines. When an email is sent, it is often wrapped in basic HTML. If a container does not explicitly define a direction, the software relies on the "First Strong Character" rule. If an email begins with an English greeting, the entire block may be treated as LTR, even if the subsequent content is primarily Hebrew. This causes the entire layout to misalign, breaking the flow for the reader.

Alignment vs. Direction

One of the most common mistakes in resolving these issues is confusing "Alignment" with "Direction." Alignment is a visual adjustment, simply pushing text to one side of a document. Direction, however, is a structural setting. In professional word processors, setting the paragraph direction to RTL changes how the software handles cursor movement and punctuation logic. Relying solely on "Align Right" while the structural direction remains LTR is the primary cause of cursor jumping and layout instability.

Professional Solutions and Tools

To achieve perfect formatting, users can employ "invisible" Unicode control characters. The Right-to-Left Mark (RLM) and Left-to-Right Mark (LRM) act as invisible anchors that force neutral characters to follow a specific direction. While these are not found on standard keyboards, they can be inserted via symbol palettes or Alt-codes to "pin" punctuation to the correct side of a phrase.

For web developers, the solution lies in structural HTML attributes. Using dir="auto" allows a browser to automatically detect the direction of a block based on its content. Additionally, the <bdi> (Bidirectional Isolate) tag is essential for isolating specific words or phrases—such as a Hebrew name within an English sentence—preventing their directionality from "leaking" and corrupting the surrounding text layout. By moving beyond visual hacks and utilizing these structural tools, creators can ensure their multi-language content remains legible and professional across all platforms.

Downloads

Episode Audio

Download the full episode as an MP3 file

Download MP3
Transcript (TXT)

Plain text transcript file

Transcript (PDF)

Formatted PDF with styling

Read Full Transcript

Episode #775: The BiDi Battle: Fixing Mixed RTL and LTR Text Chaos

Daniel Daniel's Prompt
Daniel
What are some tips for managing multi-language formatting more effectively, particularly when mixing right-to-left (RTL) languages like Hebrew or Arabic with left-to-right (LTR) languages like English? It can be a constant challenge to keep text properly formatted in mainstream applications and email clients. Are there specific techniques or app recommendations that can help avoid these formatting issues and ensure that mixed-language content displays correctly?
Corn
Hey everyone, welcome back to My Weird Prompts. I am Corn, and I am here in our Jerusalem studio with my brother and resident technical wizard.
Herman
Herman Poppleberry, at your service. It is truly great to be back in the studio, Corn. There is something about the light in Jerusalem this time of year that just makes you want to sit down and solve some complex infrastructure problems.
Corn
It really is a beautiful morning. But today, we are diving into a topic that hits very close to home for us. Living here, we are constantly switching between languages—Hebrew, English, sometimes a bit of Arabic or French—and that brings up a technical headache that most people in the strictly English-speaking world might never even consider. Today's prompt comes from Daniel, a long-time listener who is currently tearing his hair out over the absolute chaos of managing multi-language formatting. Specifically, he is talking about the nightmare of mixing Right-to-Left languages, or R-T-L, like Hebrew or Arabic, with Left-to-Right languages, or L-T-R, like English.
Herman
Oh, Daniel is speaking my language here, quite literally. This is one of those things that seems like it should have been solved thirty years ago, yet here we are in February of two thousand twenty-six, still wrestling with periods that jump to the wrong side of the sentence and parentheses that look like they are facing the wrong way. It is a fascinating, if incredibly frustrating, intersection of linguistics, software engineering, and the inherent limitations of the Unicode Bidirectional Algorithm.
Corn
It really is a struggle. I think anyone who has tried to type a Hebrew sentence and then insert a single English technical term—like "cloud computing" or "interface"—knows exactly what Daniel is talking about. You type the English word, and suddenly the whole line flips, or your cursor starts behaving like it is possessed by a ghost, jumping three words back when you press the right arrow key. So, Herman, let us start with the "why." Why is this still so difficult for modern applications to handle in two thousand twenty-six?
Herman
It comes down to the way computers actually process and store text versus how they display it. Most people think of text as just a string of characters on a screen, but behind the scenes, there is a massive logical framework called the Unicode Bidirectional Algorithm, or BiDi for short. This algorithm is the brain responsible for deciding the order in which characters are displayed. You see, the computer stores the characters in "logical order"—the order in which you typed them. But it has to display them in "visual order."
Corn
And that translation from logical to visual is where the gears start grinding.
Herman
Exactly. Most characters have what we call an inherent direction. English letters are inherently Left-to-Right. Hebrew and Arabic letters are inherently Right-to-Left. The algorithm sees a Hebrew letter and says, "Okay, I know where this goes." But then you have what we call "neutral" characters. These are your spaces, your numbers, and your punctuation marks like periods, commas, and parentheses. These characters are the chameleons of the text world. They do not have a direction of their own; they are supposed to take on the direction of the text surrounding them.
Corn
Right, and those neutral characters are where the trouble starts, because the computer has to guess which direction they should follow. And as we know, computers are often very bad at guessing intent.
Herman
Precisely. A period does not know if it is an English period or a Hebrew period. It just takes its cues from the characters around it. If you have a Hebrew sentence that ends with an English word, and then you put a period, the algorithm often gets confused. It sees the English word as the most recent "strong" directional cue. So it thinks, "Okay, we are in Left-to-Right mode now," and it puts the period to the right of the English word. But in a Hebrew context, that period actually belongs at the far left of the entire line. So to the reader, it looks like the period is hanging out in the middle of the sentence, right after the English word, while the rest of the Hebrew text continues to its left.
Corn
It is incredibly jarring. It breaks the flow of reading entirely. It is like hitting a speed bump in the middle of a highway. And Daniel mentioned something interesting in his prompt about email clients, specifically calling out Edison Mail. He noted that even in apps that are generally considered high-quality, a single English word can break the entire right-to-left flow of an email. Why are email clients particularly bad at this compared to, say, a dedicated word processor?
Herman
Email is the "Wild West" of formatting, Corn. When you send an email, you are essentially sending a little bundle of Hypertext Markup Language, or H-T-M-L, and maybe some Cascading Style Sheets, or C-S-S. But you have zero control over the rendering engine the recipient is using. One person might be reading your email on Outlook for Windows, another on Gmail in a Chrome browser, and another on a mobile app like Edison or Spark. Each one of those engines handles directionality slightly differently.
Corn
And I imagine the "container" of the email matters a lot too.
Herman
It is the most important part. If the email client does not explicitly wrap the text in a container—like a "div" or a "paragraph" tag—that says, "This entire block is Right-to-Left," the algorithm just does its best guess based on the first character it sees. This is the "First Strong Character" rule. If your email starts with a greeting in English, like "Hi Daniel," the algorithm might decide the whole paragraph is Left-to-Right, even if the next fifty words are in Hebrew. Suddenly, your Hebrew text is all aligned to the left, and your punctuation is flying all over the place.
Corn
That explains why so many people resort to those desperate hacks Daniel mentioned, like transliterating Hebrew words into English letters or using all caps to make things stand out. But those are not great solutions. They feel like a step backward for human communication. So let us get into the actual techniques. If I am writing an email or a professional document and I need it to look perfect in both languages, what are the actual tools at my disposal in two thousand twenty-six?
Herman
The most powerful tool, and the one that almost no "normal" user has ever heard of, are the invisible Unicode control characters. Specifically, the Right-to-Left Mark, or R-L-M, and the Left-to-Right Mark, or L-R-M. Think of these like invisible anchors with a very strong personality. In the world of Unicode, these are zero-width characters that have a "strong" directional identity but no visual representation.
Corn
So they are like ghosts that tell the other characters where to sit?
Herman
That is a great way to put it. If you are writing in Hebrew and you insert an English word, and you want the following period to stay on the left side where it belongs, you can insert a Right-to-Left Mark immediately after that period. It tells the computer, "Hey, I know that last word was English, but we are still fundamentally in a Right-to-Left context. Put this period on the left!" There is also a newer one called the Arabic Letter Mark, or A-L-M, which was introduced in Unicode six point three. it behaves like an Arabic character and is even better for handling numbers in Arabic strings.
Corn
Okay, but Herman, how does a normal human being actually type an invisible character? Most keyboards do not have a button for "Right-to-Left Mark" next to the spacebar.
Herman
That is the catch, and it is why people find this so frustrating. On a Mac, you can find them in the "Emoji and Symbols" palette if you search for "R-L-M." On Windows, you can use Alt-codes—holding Alt and typing eight-two-zero-seven on the number pad for R-L-M. But for most people, the easiest way is to use a specialized utility. I actually keep a little "sticky note" on my desktop with those two characters just sitting there, so I can copy and paste them whenever I need them. There are also browser extensions like "R-T-L Fixer" that can insert them for you. It sounds like a hassle, but once you start using them, it is like a magic wand for fixing broken punctuation.
Corn
It really feels like something that should be built into the interface of every text editor. I know that in professional layout software like Adobe InDesign or Affinity Publisher, they have much more robust tools for this. They have "World-Ready Composers" that handle this logic beautifully. But for the average person using Google Docs or Microsoft Word, it is a constant struggle. Speaking of Word and Google Docs, are there specific settings in those mainstream apps that we should be looking for?
Herman
Yes, and this is a crucial distinction that many people miss: the difference between Alignment and Direction. This is my number one tip for Daniel. Most people use the "Align Right" button to make their Hebrew text look correct. But alignment is just a visual trick. It is like pushing a stack of papers to the right side of a desk. Direction, however, is structural. In Microsoft Word or Google Docs, you need to find the "Paragraph Direction" buttons. They usually look like a little paragraph symbol—a pilcrow—with an arrow pointing either left or right.
Corn
I have seen those! I always thought they were just another way to align text.
Herman
Common mistake! When you set the direction to Right-to-Left, the app changes its entire behavior. The cursor movement becomes logical for Hebrew, the "Home" and "End" keys switch their functions, and the punctuation handling becomes much more intelligent. If you just use "Align Right" while the direction is still set to Left-to-Right, you are fighting the software. The cursor will move in the opposite direction of where you think it should go, and your parentheses will likely be backwards.
Corn
That is a huge tip. I have spent so many hours fighting with a cursor that seems to have a mind of its own because I was aligned right but the direction was still set to L-T-R. Now, what about the web? Daniel mentioned C-S-S in his prompt. If someone is building a website, a blog, or even a sophisticated email template, how can they ensure their mixed-language content does not fall apart for the reader?
Herman
For web developers and designers, the gold standard is the "dir" attribute in H-T-M-L. You should never just use "text-align: right" in your C-S-S and call it a day. You should wrap your Right-to-Left content in a tag—like a "section" or a "div"—with "dir" equals "R-T-L." But even better, there is a relatively new value called "auto." If you use "dir" equals "auto," the browser will actually look at the first character with strong directionality in that specific element and decide the direction of the block for you. It is surprisingly effective for user-generated content like comments or forum posts.
Corn
Does that work for individual sentences within a paragraph? Like if I have a mostly English paragraph with one Hebrew quote?
Herman
For that, you want to use the "B-D-I" tag—the Bidirectional Isolate element. This is a lifesaver. It tells the browser, "Treat the text inside this tag as its own little island. Do not let its directionality leak out and affect the punctuation or the words around it." It is perfect for when you are dropping a Hebrew name or an Arabic brand into an English sentence. It prevents that word from flipping the entire line's logic. And in C-S-S, you can achieve similar results with the "unicode-bidi" property set to "isolate."
Corn
That sounds like exactly what Daniel needs for his email issues, though applying custom C-S-S to an email is notoriously difficult because so many clients strip it out for security reasons. Let us talk about specific app recommendations. Are there any apps out there that are famously good at this? Or any that we should avoid if we are doing heavy multi-language work?
Herman
It is interesting, Corn. Some of the best apps for this are the ones that have to serve massive, diverse global audiences. WhatsApp is actually quite good at bidirectional text. Because they have hundreds of millions of users in the Middle East, North Africa, and South Asia, they have put a lot of work into making sure that when you mix Arabic and English, it just works. Telegram is also fairly robust. On the professional side, Slack has improved quite a bit, though it still has its moments where a code snippet will mess everything up.
Corn
What about note-taking apps? I know Notion has a huge following, and Daniel mentioned he uses it for his project management. I have heard mixed things about their Right-to-Left support.
Herman
Notion is a classic example of the "Silicon Valley Blind Spot." For years, their Right-to-Left support was almost non-existent. They have improved it recently—you can now trigger R-T-L blocks—but it still feels like a secondary feature tacked on. If you are doing serious, long-form writing in Hebrew or Arabic, you might find yourself frustrated. For that, I always recommend "Mellel." It is a word processor specifically designed for scholars and multilingual writers. It is the gold standard for R-T-L support.
Corn
I have heard of Mellel. It is a bit of a "power user" tool, right?
Herman
Very much so. But if you are writing a thesis in Hebrew with English citations, it is the only tool that won't make you want to throw your computer out the window. Another great option for the modern era is "Obsidian." While it doesn't have perfect R-T-L support out of the box, it has a fantastic community plugin called "R-T-L Support." It gives you a dedicated toggle for every single note and even allows you to set direction on a per-line basis using specific Markdown syntax.
Corn
That is great for personal notes, but the email problem Daniel mentioned is still the big one. If I am using an Android phone, like he is, and I am finding that my email client is failing me, is there a better alternative to Edison Mail?
Herman
Honestly, the official Gmail app is generally the most robust. Google has invested more in internationalization than almost any other company. If you use the official Gmail app, it usually detects the language correctly and applies the right directionality. But if you want something more privacy-focused, you should look at "Proton Mail." They have made significant strides in their R-T-L rendering in the last two years. Another trick for mobile users is the keyboard itself. Some keyboards, like Gboard or Microsoft SwiftKey, have better logic for handling the transition between languages. Sometimes, the way the keyboard "injects" the characters into the text field can actually influence how the app decides to format them.
Corn
That is a really interesting point. I have noticed that when I switch from the standard iOS keyboard to a third-party one, the behavior of the cursor sometimes changes even within the same app. Herman, I want to go back to something Daniel said about the dominance of English terminology. This is so common in tech, medicine, and law. You are writing in Hebrew, but every third word is an English acronym or a specific term that has no direct translation. When you have that much mixing, does the whole Right-to-Left system just start to break down?
Herman
It can reach a "tipping point." There is a point of critical mass where if you have more English than Hebrew in a sentence, the BiDi algorithm might get "confused" and decide the whole sentence is English. This is where those invisible marks—the R-L-M and L-R-M—become essential. But there is also a stylistic choice to consider. Sometimes, if you are using that much English, it might actually be cleaner to format the entire document as Left-to-Right and just let the Hebrew words be the outliers. It is not ideal, but for a technical manual, it can be more readable than a sentence that is constantly zig-zagging back and forth.
Corn
That feels like a surrender, though! We want our languages to coexist peacefully. I wonder if there is a future where A-I can help with this. We are seeing A-I-powered text editors like Lex and others now. Could an A-I intelligently insert those invisible Unicode marks for us as we type?
Herman
I think that is exactly where we are headed. Imagine a text editor that doesn't just see characters, but understands the context of what you are writing. It sees you are writing a Hebrew sentence, it sees you are inserting a technical English term, and it automatically wraps that term in a directional isolate or adds a Right-to-Left Mark after the trailing punctuation. It would take the cognitive load off the user. Right now, we have to be part-time linguists and part-time software engineers just to send a clear email. In the next few years, I expect "BiDi-aware" A-I models to handle this silently in the background.
Corn
It really does feel that way. Let us talk about numbers for a second. Numbers are another huge pain point for Daniel. In Hebrew and Arabic, we read the text right to left, but we write numbers left to right. So if I am writing a date or a phone number in the middle of a sentence, it is a mini-bidirectional event within the larger sentence.
Herman
Oh, don't even get me started on phone numbers. This is the "Final Boss" of R-T-L formatting. If you have a phone number with a plus sign for an international code, like plus nine-seven-two, the plus sign often ends up at the end of the number instead of the beginning because the algorithm sees the plus sign as a neutral character. The same thing happens with mathematical equations. If you are trying to write "two plus two equals four" in the middle of an Arabic sentence, you can end up with "four equals two plus two," which is just confusing for everyone.
Corn
So what is the fix for that? Is it more invisible marks?
Herman
Usually, yes. The Left-to-Right Mark is your best friend here. You place it right before the number or the equation to "force" the computer into L-T-R mode for that specific string. There is also a specific Unicode character called the "Number Terminator" that can help, but it is less widely supported. For most people, the safest bet is to wrap the number or the equation in those L-R-M marks. It is like putting a little protective bubble around the number so the surrounding Hebrew or Arabic text doesn't "crush" it.
Corn
It sounds like the overarching theme here is that we have to be proactive. We can't just trust the apps to get it right because, frankly, most of them weren't designed with our part of the world as the primary focus.
Herman
That is exactly it. Most of the software we use was built in Silicon Valley or Seattle by people who speak English and maybe a little bit of Spanish or French. All of those are Left-to-Right languages. The core architecture of the internet—the very way H-T-M-L and C-S-S were conceived in the early nineties—was built on the assumption that text flows from left to right. We are essentially retrofitting a system that wasn't designed for us. But the good news is that the standards are there. The Unicode Consortium has thought about all of this. The problem is just the implementation in the specific apps we use every day.
Corn
So, if we were to give Daniel a checklist of things to try when he's fighting with his email formatting on his phone or his laptop, what would be at the top of that list?
Herman
Number one: Always use the Paragraph Direction buttons, not just the Alignment buttons. This is the single most important change you can make. If your email app doesn't have those buttons, it might be time to find a new email app. Number two: Learn how to use the Right-to-Left Mark and the Left-to-Right Mark. Keep them in a note on your phone or a "text expansion" shortcut so you can copy and paste them when a period or a parenthesis goes rogue.
Corn
And for the web-savvy folks?
Herman
Number three: If you are doing any kind of web work, use "dir" equals "auto" and the "unicode-bidi: isolate" property in your C-S-S. It will save you hours of debugging. And number four: Don't be afraid to use a little bit of extra space. Sometimes, just putting a space between an English word and a Hebrew punctuation mark can give the algorithm enough "breathing room" to make the right choice. It is not always grammatically perfect, but it is often much more readable.
Corn
Those are great, practical tips. I'd also add that if you're sending a really important document—like a contract or a formal letter—where the formatting must be perfect, maybe just send a P-D-F. It's the only way to be absolutely sure that what you see on your screen is exactly what the other person sees on theirs.
Herman
That is the ultimate fallback! The P-D-F is the universal peacemaker in the language wars. But even then, a word of caution: make sure your P-D-F generator supports bidirectional text. Some cheap "Print to P-D-F" drivers will actually scramble the Hebrew text during the conversion process, turning it into a "visual" order that can't be searched or copied correctly. Always use a high-quality generator like the one built into Microsoft Word or Adobe Acrobat.
Corn
It never ends, does it? It is a constant battle for clarity. But I think we've given some really solid ground for Daniel and anyone else dealing with this to stand on. It's about taking control of the structure of the text, not just the appearance.
Herman
Exactly. It's about understanding the logic of the machine so you can bend it to your will, rather than letting it mangle your thoughts. It's a bit of a dance, but once you know the steps—once you understand how those "strong" and "neutral" characters interact—it gets much easier. You stop feeling like the computer is broken and start feeling like you are just speaking its secret language.
Corn
I think that's a perfect place to wrap up the technical side of this. It's a niche topic for some, but for millions of people in the Middle East and beyond, it's a daily reality. Daniel, thanks for bringing this up. It's something we deal with every time we sit down at our desks here in Jerusalem, and it's good to finally give it some airtime.
Herman
Definitely. And if anyone out there has discovered a specific app or a clever little hack that we didn't mention—maybe a new Android utility or a specific keyboard setting—we'd love to hear about it. This is a problem that we solve together, one invisible character at a time.
Corn
Absolutely. And hey, if you've been enjoying these deep dives into the weird and wonderful prompts Daniel and our other listeners send our way, we would really appreciate it if you could leave us a review on your favorite podcast app. Whether it's Spotify, Apple Podcasts, or wherever you listen, those ratings and reviews really do help more people find the show.
Herman
They really do. It makes a huge difference in the algorithm, which, hopefully, is better at ranking podcasts than it is at formatting Hebrew text!
Corn
One can only hope! You can find us at my-weird-prompts-dot-com, where we have our full archive of over seven hundred episodes. There is an R-S-S feed there for subscribers and a contact form if you want to get in touch. You can also reach us directly at show-at-my-weird-prompts-dot-com.
Herman
We love hearing from you all. Whether you have a question about Unicode, a comment on our Jerusalem bakery recommendations, or a weird prompt of your own, don't be a stranger. We read every single email that comes in.
Corn
Well, Herman, I think we've successfully navigated the bidirectional minefield for today. Thanks for bringing the expertise and for explaining the "ghosts" in the machine.
Herman
Any time, Corn. It was a pleasure to nerd out on this. It is a problem worth solving.
Corn
Thanks for listening to My Weird Prompts. We'll be back soon with another exploration of the ideas, the tech, and the quirks that make life interesting. Until then, I'm Corn.
Herman
And I'm Herman Poppleberry.
Corn
Take care, everyone.
Herman
Goodbye!

This episode was generated with AI assistance. Hosts Herman and Corn are AI personalities.