Line indentation in iText 7? - itext

I am working on a program to convert a txt file to a pdf with alot of changes on line indentation. However, I am unable to find the exact command that can achieve this in iText 7. I am aware that in iText 5 there were methods such as setIndentationLeft() and setIndentationRight() of paragraph object which allowed explicit indenting, but this is not available in the latest version. The latest version only offers setFirstLineIndent() which doesn't suffice for my needs.
This is what I wanna achieve:
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
As you can see, line starts with different indentation. I have considered the use prepending spaces to the line but I find that very inefficient. How can I go about solving this?

Answering my own question to help others with same problem.
There are 3 ways to solve this problem:
1) Since I would like to set it for each line in the paragraph you can split the lines of text into different chunks and then set indent for that individually. Once done you can add it to your document.
2) Though iText5 is outdated it can still be used to solve many problems. If you are using Maven as your build tool then simply add the below code to your dependencies and you can then start using the left and right indent methods.
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.10</version>
</dependency>
3) You can also use a table cell approach, where you can add the text inside a given cell and set appropriate margins, see below.
Table table = new Table(1);
Paragraph right = new Paragraph("This is right, because we create a paragraph with an indentation to the left and as we are adding the paragraph in composite mode, all the properties of the paragraph are preserved.");
right.setMarginLeft(20);
Cell rightCell = new Cell().add(right);
table.addCell(rightCell);
doc.add(table);
This will be rendered as folllows.
I would personally discourage the use of the second method but if it can solve your problem then there's nothing stopping you.

Paragraph.setMarginLeft();
Paragraph.setMargins();
use these to adjust your indentation

Related

Autohotkey script for copying specific content inside the brackets by clicking anywhere inside these brackets

I want to make an Autohotkey script, so I ask you for a little help.
I work as a transcriptionist, and in my text I often have timecodes in the following format (00:00:00). I need a script what will help me to copy to clipboard a timecode in the format 00:00:00 (without brackets) by clicking to any place inside these brackets (for example Alt+LClick).
Now I use the following script, but it is hardcoded and I must click exactly in the middle of the timecode, otherwise it doesn't work:
!LButton::
Send {Click 2}
Sleep 100
Send {Right 4}{Shift Down}{Left 8}{Shift Up}
Send ^c
return
So I want an improved and more versatile script. Thank you in advance for any help.
I would use something like this if you want to select one by one.
~LButton:: ; Hold the left button to select
now := A_TickCount
While GetKeyState( "LButton", "P" )
if( A_TickCount - now > 300 ) {
; Just incremented the range
Send {AltUp}{Right 10}{Shift Down}{Left 20}{Shift Up}
Send ^c
Sleep, 100
; Filter characters between "(" and ")"
Clipboard := StrReplace( StrReplace( RegExReplace( Clipboard, "[^\)]+(\(|$)"), ")" ), "(") ; Can be better than this, but im not good with regex
Send {Right}
; Just for test
ToolTip % Clipboard
Sleep, 1000
Tooltip
}
Return
Or you can select the entire text and filter all result at once.
F1:: ; ANY HOTKEY YOU WANT
Clipboard := "Lorem Ipsum is simply (00:00:57) dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived (00:01:51) not only five centuries, but also the leap into electronic (01:23:11) typesetting, remaining essentially (00:10:23) unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum"
Clipboard := StrReplace( StrReplace( RegExReplace( Clipboard, "[^\)]+(\(|$)","`n"), ")" ), "(") ; Can be better than this, but im not good with regex
ToolTip % Clipboard
Sleep, 1000
Tooltip
Return

Is there a way to fix SwiftLint's trailing whitespace violation?

I have a method that has has a closing bracket at line 20, I want my next method to start at line 23 because I want line 22 to have a comment. This will leave line 21 to have the one space between these two methods, but because line 22 is a comment SwiftLint will throw a "Trailing Whitespace Violation". Is there any way to fix this?
Trailing whitespace violation doesn't mean that there is an empty line, but rather that there is some unnecessary whitespace (not linebreaks, but tabs/spaces).
You can automatically fix trailing whitespacing by turning on the relevant feature in Xcode. You can find it in Xcode Preferences: Text Editing/Editing/While editing, turn on both "Automatically trim trailing whitespace" and "Including whitespace-only lines".

How to add a force line-break in a draw2d TextFlow

How do I add a forced line-break within a draw2d TextFlow figure.
I build a IFigure by adding several different objects. Amongst other things I add a FlowPage containing a TextFlow. But I could not find an option to force line-breaks at specific locations.
Figure fig = new Figure();
fig.setLayoutManager(new FreeformLayout());
FlowPage flow = new FlowPage();
flow.setSize(100,100);
TextFlow text = new textFlow("A rather long text without any line-breaks. Lorem Ipsum dolor sit amet.");
flow.add(text);
fig.add(flow);
fig.setSite(100,100);
The common LineFeed character \n solved this problem. Inserted somewhere inside the String it forces a line-break.

Strange indentation within emacs org mode src block

I am trying to edit a document using org mode. The document represents a blog post. I need the body of the post to be in markdown so I am using a src block.
The problem is that when I alter or save the text in the src block after opening it in another buffer using C-c ', there is some type of automatic indention that is applied that messes up my formatting.
Here are the details.
Beginning with with a buffer that looks like this:
* title...
* body
#+begin_src markdown
Some text.
#+end_src
I press C-c ' and get a new buffer where I edit the markdown text to look like this in markdown mode:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam
lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam
viverra nec consectetur ante hendrerit. Donec et mollis
dolor. Praesent et diam eget libero egestas mattis sit amet vitae
I used M-q to format the text lines so there are newlines at the end of each line above. There are also no initial spaces.
Now if I either press C-x C-s to save or C-c ' the formatting above is changed to look like this:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam
lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam
viverra nec consectetur ante hendrerit. Donec et mollis
dolor. Praesent et diam eget libero egestas mattis sit amet vitae
Every other line is indented two spaces.
I have tried this with other src types, such as using:
#+begin_src javascript
I get similar indentation, though it doesn't alternate. Two spaces are added to every line, instead.
I am assuming that this isn't a bug but my Internet searches and looks through the documentation haven't turned up the answer.
I'm using GNU Emacs 23.4.1 on Arch Linux with Org-mode 6.33x.
I also tried using the latest version of org-mode from git 7.8.05.
The variable you're looking to customize is org-edit-src-content-indentation
org-edit-src-content-indentation is a variable defined in `org-src.el'.
Its value is 2
Documentation:
Indentation for the content of a source code block.
This should be the number of spaces added to the indentation of the #+begin
line in order to compute the indentation of the block content after
editing it with M-x org-edit-src-code. Has no effect if
`org-src-preserve-indentation' is non-nil.
You can discover this for yourself by:
C-h k C-c ' → org-edit-special
M-x apropos-variable org-edit
On first glance this looks like the auto-indentation of blocks in Org. I do know that by default it tries to indent the body of the block to be two spaces in from the #+begin and #+end lines.
However, I would recommend updating to a newer version of Org. 6.33x is very old and there have been changes to code blocks in the meantime. It is available in the AUR (Here). However I would recommend using git to pull version 7.8.03 at the moment, there was a mistake made while releasing 7.8.04 and then 7.8.05 and they are in the midst of fixing it. Alternately, the version bundled with Emacs24 is stable and much more up to date.

Org-mode & Latex export: Any way to put short & long names in sectioning commands? Workarounds?

In standard Latex, one can use something like...
\section[short head]{A longer and more meaningful heading version for the section}
...that gives both a long and short version of a section (or other sectioning command) Thus, allowing for both meaningful sectioning 'titles' and, also, reasonable-looking running heads, TOCs, beamer navigation, etc..
Is there any way to easily achieve this in org mode? (That is without hard coding the sectioning commands in LATEX snippets and, thus, defeating most of the flexibility of changing sectioning levels and repurposing content for beamer, book, and article classes that is my reason for wanting to try orgmode, in first place?)
I tried a "workaround" that did not work. I tried editing the possible latex export classes by adding another class to org-export-latex-classes. This new class changes sectioning commands from \section{%s} to \section%s(EDIT-Fixed typo in slashes). Then I tested using [short]{longer version} in orgmode sections of the file. It worked, except it acted as if the longer version section heading was just "{" and "longer version" was body text! What is up with that?
Since version 8.0 the "org-export-latex-classes" strategy won't work anymore.
Instead, and dare I say much more elegantly, you can set the ALT_TITLE property for the heading.
See http://orgmode.org/manual/Table-of-contents.html.
The following org code:
* The Long Title of Section 1
:PROPERTIES:
:ALT_TITLE: Section 1
:END:
Lorem ipsum.
** The Long Title of Subsection 1-1
:PROPERTIES:
:ALT_TITLE: Subsection 1-1
:END:
Dolor sit amet.
will export to LaTeX as:
[...]
\section[Section 1]{The Long Title of Section 1}
\label{sec-1}
Lorem ipsum.
\subsection[Subsection 1-1]{The Long Title of Subsection 1-1}
\label{sec-1-1}
Dolor sit amet.
You had the right idea with creating your own LaTeX class. The problem lies with the way the templates are filled by the default org-fill-template function. I'm not so great with Lisp, but this this hack will do the trick. Add the following to your .emacs file:
(defun my-section (level text)
(let* ((in "") (out "")
(short-title (if (string-match "\\[.*\\]" text)
(substring text (match-beginning 0)
(match-end 0))
nil)))
(if short-title (setq text (substring text (match-end 0) -1)))
(setq in (org-fill-template
"\\section%S{%s}"
(list (cons "S" (or short-title ""))
(cons "s" (or text ""))))
out (copy-sequence "\\end{section}"))
(cons text (list in out in out))))
(add-to-list 'org-export-latex-classes
'("test"
"\\documentclass{article}"
my-section))
This declares a new latex class by adding a "test" class to the org-export-latex-classes. Here we declare, instead of the normal \\section{%s} stuff a function that takes two parameters --- the current level and the headline text --- and returns a modified cons cell. Some details of this information can be found in org-latex-export.el.
Above the adding to the list is where we actually define the function. This is honestly a hacky version, and I pulled a lot from the org-beamer-sectioning function in org-beamer.el file. This function basically searches the headline for anything that is like a LaTeX short label (i.e. [....]) removes it from the headline and sticks it before the actual section label. Right now this hack will only generate \section statements, no matter how deep the level - if you want something more intelligent like \chapter or \subsection or even unnumbered items, you'll need to do some more Lisping; again, see org-beamer.el for some help.
This bit of org-mode code
#+latex_class: test
* [short 1] this is 1 star
test
** this is a 2 star
test
*** [short 3] this is a 3 star
test
**** what happens
exports to LaTeX as (only relevant sections shown here):
\section[short 1]{ this is 1 star}
\label{sec-1}
test
\section{ this is a 2 star }
\label{sec-1-1}
test
\section[short 3]{ this is a 3 star}
\label{sec-1-1-1}
test
\section{ what happens }
\label{sec-1-1-1-1}
\end{section}
\end{section}
\end{section}
\end{section}
Although it's not a straight org-mode solution, it seems to work and can be a starting point for you. One of these days I might try to write it up properly and get it folded into the org-mode distribution.
It is possible to use the following commands in latex to define the text that should appear in the header to replace section names. But the TOC will still contain the original names.
\chaptermarks
\sectionmarks
\subsectionmarks
...
So, in org-mode you can write
* Long section title
#+LaTeX: \sectionmark{Short title}
edit: it actually doesn't work on the very page where the section name appears. On this one only, the full name is still put in the header.