# PdfHyphenator class

> Finds where words may break with a hyphen, by Liang's pattern algorithm as TeX defines it (Liang 1983, and The TeXbook, appendix H). Give one to...

Namespace: [PdfNetStack.Drawing](https://www.jadev-corp.com/api/pdfnetstack-drawing/)  
Assembly: PdfNetStack.dll  
Package: `PdfNetStack`

Finds where words may break with a hyphen, by Liang's pattern algorithm as TeX defines it
(Liang 1983, and The TeXbook, appendix H). Give one to [Hyphenator](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfparagraph/#PdfNetStack_Drawing_PdfParagraph_Hyphenator)
to hyphenate a paragraph, or use [InsertSoftHyphens](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfhyphenator/#PdfNetStack_Drawing_PdfHyphenator_InsertSoftHyphens_System_String_) on text of your own. The core
library has the algorithm and no patterns: the <code>PdfNetStack.Hyphenation</code> package has them
for many languages, and [Create](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfhyphenator/#PdfNetStack_Drawing_PdfHyphenator_Create_System_Collections_Generic_IEnumerable_System_String__System_Collections_Generic_IEnumerable_System_String__) takes any others.

```csharp
public sealed record PdfHyphenator : IEquatable<PdfHyphenator>
```

**Inheritance**

[object](https://learn.microsoft.com/dotnet/api/system.object) ← 
[PdfHyphenator](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfhyphenator/)

**Implements**

[IEquatable&lt;PdfHyphenator\>](https://learn.microsoft.com/dotnet/api/system.iequatable\-1)

## Examples

<pre><code class="lang-csharp">// Your own patterns, in TeX's format, and exceptions in \hyphenation's.
PdfHyphenator h = PdfHyphenator.Create(patterns, ["ta-ble", "project"]) with { MinLeft = 2, MinRight = 3 };
string text = h.InsertSoftHyphens("Hyphenation");   // "Hy\u00ADphen\u00ADation"</code></pre>

## Remarks

A hyphenator is immutable and safe to share between threads. Letters fold to lower case by
invariant rules, so results do not depend on the current culture. These are left alone: words
with a soft hyphen (U+00AD), whose breaks are the author's; words joined to a digit, or holding a
capital past the first letter; words of all capitals, unless [HyphenateAllCaps](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfhyphenator/#PdfNetStack_Drawing_PdfHyphenator_HyphenateAllCaps);
anything that looks like a web address, e-mail address or file path; words with letters outside
the patterns' alphabet; and words over 64 letters, as in TeX.

## Properties

### <a id="PdfNetStack_Drawing_PdfHyphenator_HyphenateAllCaps"></a> HyphenateAllCaps

Whether words of all capitals are hyphenated too. Default false: most are acronyms and names.

```csharp
public bool HyphenateAllCaps { get; init; }
```

#### Property Value

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

### <a id="PdfNetStack_Drawing_PdfHyphenator_MinLeft"></a> MinLeft

The fewest letters before a hyphen (TeX's \lefthyphenmin). Default 2.

```csharp
public int MinLeft { get; init; }
```

#### Property Value

 [int](https://learn.microsoft.com/dotnet/api/system.int32)

#### Exceptions

 [ArgumentOutOfRangeException](https://learn.microsoft.com/dotnet/api/system.argumentoutofrangeexception)

The value is less than 1.

### <a id="PdfNetStack_Drawing_PdfHyphenator_MinRight"></a> MinRight

The fewest letters after a hyphen (TeX's \righthyphenmin). Default 3.

```csharp
public int MinRight { get; init; }
```

#### Property Value

 [int](https://learn.microsoft.com/dotnet/api/system.int32)

#### Exceptions

 [ArgumentOutOfRangeException](https://learn.microsoft.com/dotnet/api/system.argumentoutofrangeexception)

The value is less than 1.

### <a id="PdfNetStack_Drawing_PdfHyphenator_MinWordLength"></a> MinWordLength

The fewest letters a word needs to be hyphenated at all. Default 5, as CSS <code>hyphens: auto</code> does.

```csharp
public int MinWordLength { get; init; }
```

#### Property Value

 [int](https://learn.microsoft.com/dotnet/api/system.int32)

#### Exceptions

 [ArgumentOutOfRangeException](https://learn.microsoft.com/dotnet/api/system.argumentoutofrangeexception)

The value is less than 1.

## Methods

### <a id="PdfNetStack_Drawing_PdfHyphenator_Create_System_Collections_Generic_IEnumerable_System_String__System_Collections_Generic_IEnumerable_System_String__"></a> Create\(IEnumerable&lt;string\>, IEnumerable&lt;string\>?\)

A hyphenator from patterns in TeX's format, such as <code>hy3ph</code> and <code>.ach4</code>, and exceptions.

```csharp
public static PdfHyphenator Create(IEnumerable<string> patterns, IEnumerable<string>? exceptions = null)
```

#### Parameters

`patterns` [IEnumerable](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable\-1)<[string](https://learn.microsoft.com/dotnet/api/system.string)\>

Letters with a digit in any gap; a dot at either end marks the edge of a word.

`exceptions` [IEnumerable](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable\-1)<[string](https://learn.microsoft.com/dotnet/api/system.string)\>?

Words with their only breaks marked, such as <code>ta-ble</code>; a word without a hyphen never breaks.

#### Returns

 [PdfHyphenator](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfhyphenator/)

#### Exceptions

 [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)

A pattern or exception is malformed.

### <a id="PdfNetStack_Drawing_PdfHyphenator_FindBreaks_System_String_"></a> FindBreaks\(string\)

Where <code class="paramref">text</code> may break with a hyphen: indexes of the characters that would start the next line, in order.

```csharp
public IReadOnlyList<int> FindBreaks(string text)
```

#### Parameters

`text` [string](https://learn.microsoft.com/dotnet/api/system.string)

#### Returns

 [IReadOnlyList](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist\-1)<[int](https://learn.microsoft.com/dotnet/api/system.int32)\>

### <a id="PdfNetStack_Drawing_PdfHyphenator_InsertSoftHyphens_System_String_"></a> InsertSoftHyphens\(string\)

The text with a soft hyphen (U+00AD) at every place it may break. Layouts, viewers and browsers honor those without a hyphenator.

```csharp
public string InsertSoftHyphens(string text)
```

#### Parameters

`text` [string](https://learn.microsoft.com/dotnet/api/system.string)

#### Returns

 [string](https://learn.microsoft.com/dotnet/api/system.string)

### <a id="PdfNetStack_Drawing_PdfHyphenator_WithExceptions_System_Collections_Generic_IEnumerable_System_String__"></a> WithExceptions\(IEnumerable&lt;string\>\)

A copy of this hyphenator that also knows these words, which take precedence over the
patterns and over earlier exceptions. [MinLeft](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfhyphenator/#PdfNetStack_Drawing_PdfHyphenator_MinLeft) and [MinRight](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfhyphenator/#PdfNetStack_Drawing_PdfHyphenator_MinRight) still
apply to them, as in TeX, and letters new to the alphabet join it.

```csharp
public PdfHyphenator WithExceptions(IEnumerable<string> words)
```

#### Parameters

`words` [IEnumerable](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable\-1)<[string](https://learn.microsoft.com/dotnet/api/system.string)\>

Words with their only breaks marked, such as <code>ta-ble</code>; a word without a hyphen never breaks.

#### Returns

 [PdfHyphenator](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfhyphenator/)

#### Exceptions

 [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)

A word is empty or holds a digit, a dot or two hyphens in a row.

## Used in

- [Fonts and text in PDF with C# and .NET](https://www.jadev-corp.com/guides/fonts-and-text/)
- [CSS support in PdfNetStack.Html](https://www.jadev-corp.com/guides/html-to-pdf/css-support/)

Source: https://www.jadev-corp.com/pdfnetstack/api/pdfnetstack-drawing/pdfhyphenator/
