Skip to content

Commit

Permalink
v1.3.4, add foldmark method to KomaLetter
Browse files Browse the repository at this point in the history
  • Loading branch information
uhoefel committed Aug 24, 2023
1 parent d10d778 commit 97b46c8
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 23 deletions.
13 changes: 13 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,18 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ The artifact can be found at maven central:
<dependency>
<groupId>eu.hoefel</groupId>
<artifactId>jatex</artifactId>
<version>1.3.3</version>
<version>1.3.4</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>eu.hoefel</groupId>
<artifactId>jatex</artifactId>
<version>1.3.3</version>
<version>1.3.4</version>
<packaging>jar</packaging>

<name>jatex</name>
Expand Down
79 changes: 59 additions & 20 deletions src/main/java/eu/hoefel/jatex/letter/KomaLetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public final class KomaLetter {
private boolean smaller = true;
private boolean clean = true;
private String[] cleanupFileExtensions = new String[0];
private String foldmarks = "TBMPL";
private String toName;
private String toStreet;
private String toCity;
Expand Down Expand Up @@ -53,24 +54,27 @@ private KomaLetter() {
//no-op
}

private static Latex setup() {
private Latex setup() {
return new Latex()
.compiler(TexCompiler.LUALATEX)
.documentclassWithOptions("scrlttr2", Map.of("version", "last"))

.usePackages("babel")

.usePackageWithOptions("microtype", Map.of("activate", "{true,nocompatibility}",
"final", "",
"tracking", "true"))
.usePackageWithOptions("microtype",
Map.of("activate", "{true,nocompatibility}",
"final", "",
"tracking", "true"))

.usePackageWithOptions("siunitx", Map.of("locale", "DE",
"separate-uncertainty", "",
"per-mode", "fraction"))
.usePackageWithOptions("siunitx",
Map.of("locale", "DE",
"separate-uncertainty", "",
"per-mode", "fraction"))

.usePackageWithOptions("csquotes", Map.of("strict", "true",
"autostyle", "true",
"german", "guillemets"))
.usePackageWithOptions("csquotes",
Map.of("strict", "true",
"autostyle", "true",
"german", "guillemets"))

.usePackages("xcolor",
"datetime2",
Expand All @@ -85,7 +89,7 @@ private static Latex setup() {
.addToPreamble("% layout definitions")
.addToPreamble(Latex.MINOR_SEPARATOR)

.addToPreamble("\\KOMAoptions{fromphone=on,fromrule=aftername,fromemail=on}")
.addToPreamble("\\KOMAoptions{fromphone=on,fromrule=aftername,fromemail=on,foldmarks="+(foldmarks != null ? foldmarks : "off")+"}")
.addToPreamble("\\SetTracking{encoding={*},shape=sc}{40}")
.addToPreamble(Latex.EMPTY_LINE)
.addToPreamble("\\newboolean{showbank}")
Expand Down Expand Up @@ -242,9 +246,35 @@ public KomaLetter user(Texable user) {
*
* @param showbank if true, show the bank info
* @return the current KomaLetter
* @deprecated Wrong name, use {@link #showBank(boolean)}
*/
@Deprecated(forRemoval = true, since = "1.3.4")
public KomaLetter showbank(boolean showbank) {
this.showbank = showbank;
return showBank(showbank);
}

/**
*Sets whether to show the bank information.
*
* @param showBank if true, show the bank info
* @return the current KomaLetter
*/
public KomaLetter showBank(boolean showBank) {
this.showbank = showBank;
return this;
}

/**
*Sets whether to show foldmarks, and which. See the corresponding chapter in the KOMAScript manual.
* Default is {@code 'TBMPL'}.
* <p>
* To deactivate the fold marks use {@code null}.
*
* @param foldmarks if true, show foldmarks
* @return the current KomaLetter
*/
public KomaLetter foldmarks(String foldmarks) {
this.foldmarks = foldmarks;
return this;
}

Expand Down Expand Up @@ -457,26 +487,31 @@ public KomaLetter cc(String... cc) {
* if an error occurred
*/
public int exec() {
if (date == null) date = LocalDate.now();
if (date == null) {
date = LocalDate.now();
}

String address = (toStreet == null ? "" : toStreet + "\\\\")
+ (toCity == null ? "" : toCity + "\\\\")
+ (toExtra == null ? "" : toExtra);

String locale = user.neededPackages().stream()
.filter(p -> p.name().equals("babel"))
.findFirst()
.orElse(new LatexPackage("babel")) // package without the option we are interested in
.options()
.getOrDefault("main", "english");
.filter(p -> p.name().equals("babel"))
.findFirst()
.orElse(new LatexPackage("babel")) // package without the option we are interested in
.options()
.getOrDefault("main", "english");

if (language != null) {
locale = language;
}

Latex tex = setup().folder(file.getParent().toString())
.filename(file.getFileName().toString());

if (user != null) tex.add(user);
if (user != null) {
tex.add(user);
}

tex.usePackageWithOptions("babel", Map.of("main", locale))
.addToPreamble(Latex.MINOR_SEPARATOR)
Expand Down Expand Up @@ -517,14 +552,18 @@ public int exec() {
tex.add(Latex.indent(1) + "\\closing{" + closing + "}");
}

if (ps != null) tex.add(Latex.indent(1) + "\\ps " + ps);
if (ps != null) {
tex.add(Latex.indent(1) + "\\ps " + ps);
}

if (encl != null) {
tex.add(Latex.indent(1) + "\\encl{");
for (String line : encl) {
tex.add(Latex.indent(2) + line + "\\\\");
}
tex.add(Latex.indent(1) + "}");
}

if (cc != null) {
tex.add(Latex.indent(1) + "\\cc{");
for (String line : cc) {
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/eu/hoefel/jatex/letter/KomaLetterTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.nio.file.Paths;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.CleanupMode;
import org.junit.jupiter.api.io.TempDir;

import eu.hoefel.jatex.EnabledIfLatexExecutable;
Expand All @@ -29,7 +30,7 @@ class KomaLetterTests {
*/
@Test
@EnabledIfLatexExecutable(compiler = TexCompiler.LUALATEX)
void testLetter(@TempDir Path folder) {
void testLetter(@TempDir(cleanup = CleanupMode.ON_SUCCESS) Path folder) {
Path file = Paths.get(folder.toString(), "letter.tex");
KomaLetter letter = KomaLetter.as(file)
.language("ngerman")
Expand Down

0 comments on commit 97b46c8

Please sign in to comment.