How to add blank lines in new commands in Latex - macros

I am using following code which uses \newcommand (macro):
\documentclass[12pt]{article}
\usepackage{color}
\usepackage{graphicx}
\begin{document}
% definition of new commands:
\newcommand{\mytitle}[1]{\LARGE\color{black}\centering\textbf{#1\newline}}
% NEWLINE WORKS IN ABOVE LINE
\newcommand{\mycode}{\small\color{green}Code:\scriptsize\leftskip30pt\color{red}\\*}%
% CANNOT ADD NEWLINE BEFORE "Code:" IN ABOVE LINE
\newcommand{\mytext}{\normalsize\color{black}\leftskip0pt}
\newcommand{\myoutput}{\small\color{green}Output:\scriptsize\leftskip30pt\color{blue}\\}%
% CANNOT ADD NEWLINE BEFORE "Output:" IN ABOVE LINE
\quote % to prevent indentation of first line;
% main text starts here:
\mytitle{Simple text, code and figure.}
\mytext
This is normal text- part 1.\\
This is normal text- part 1.\\
This is normal text- part 1.\\
\mycode
This is code line 1.\\
This is code line 2.\\
This is code line 3.\\
\myoutput
This is output line 1.\\
This is output line 2.\\
This is output line 3.\\
\mytext
This is normal text- part 2.\\
This is normal text- part 2.\\
This is normal text- part 2.\\
\mycode
This is code part 2.\\
This is code part 2.\\
This is code part 2.\\
\myoutput
This is output part 2.\\
This is output part 2.\\
This is output part 2.\\
\mytext
The last line in normal text.\\
\end{document}
Though the output is all right, I am not able to enter blank lines before "Code:", "Output" and text parts:
I have tried to use \\ \newline and \linebreak[1] to add blank lines at points marked by arrows, but they all produce following error:
There's no line here to end.
How can I add blank lines before code, output and text parts of text? Thanks for your help.

As documented here, you can use one of the following commands depending on how much space you want to skip:
\smallskip
\medskip
\bigskip
or the more flexible one: \vspace{length-of-space}
Now coming to what you have tried.
Is it possible to use \\, \newline and \linebreak here?
Yes but you need something before those commands since, as the error message says, there is no line to end.
You can use a non-breaking space, ~, before those commands.
So all of the following would also work:
~\\
~\newline
~\linebreak
Another relevant post: Lengths and when to use them

Related

Blue zig-zag line still shows even after words added to Ignore Words list in Code Spell Check extension in VS Code

I am using an extension in VS Code called Code Spell Check, but when I add some words in C Spell: Ignore Words list, the blue zig-zag line under those words is not removed. Why is it happening?
Blue zig-zag line still shows:
Ignore words list:

Combining two commands in a new command in Latex

I am trying to create a new command that will replace text with a blank line to write on. Essentially, the lovechild of, \underline and \phantom if it can be toggled on and off that would be even better but I seem to have a misunderstanding of how macros work in latex.
My crappy code is below
\newcommand{\rmv{}}{\Underline{\phantom{}}}
You're macro needs to know what text you want in the gap, so it needs an argument. The syntax to pass argument to the new macro is
\newcommand\macroname[number of arguments]{use the argument with #1 etc.}
\documentclass{article}
\newif\ifgaps
\gapstrue % comment/uncomment to toggle
\newcommand{\rmv}[1]{%
\ifgaps%
\underline{\phantom{#1}}%
\else%
#1%
\fi%
}
\begin{document}
test \rmv{test} test
\end{document}
(to automatically create two versions of your pdf with and without the gaps, you could use something similar to https://topanswers.xyz/tex?q=583 )

i have this book called learning python the hard way and i have queries regarding that

my code and the terminal .
file = "ex25.py", line 27
words=sort_sentence(sentence)
IndentationError: unindent does not match any other indentation level
The code I wrote in ex25 is:
def print_first_and_last_sorted(sentence):
words =sort_sentence(sentence)
print_first_word(words)
print_last_word(words)
After you define function with the first line, in the second line you need to use proper indentation or spaces. The standard is 4 spaces (4 space keystrokes) or 1 tab.
def print_first_and_last_sorted(sentence):
words =sort_sentence(sentence) # This line and next should be spaced 4 times with
print_first_word(words) # respect to the above one
print_last_word(words)
Your second line is not indented properly. You can compare it with the next lines. They all should be vertically parallel at their start points.
I can't comment but from both the edit and the original post, therefore I can't tell what the indentation actually is.
Python indentation works like blocks of code, similar to other languages except without the curly braces. For example:
def print_first_and_last_sorted(sentence):
words = sort_sentence(sentence)
print_first_word(words)
print_last_word(words)
You may have mixed up spaces & tabs. From this answer, try searching and replacing to replace them with a few spaces.

Ignoring blank lines in Sublimerge

I'm loving sublimerge. But after looking through the docs I can't find any way to ignore blank lines.
In the image below, you can see a difference indicated by the green and pink arrows. The description just says "Right Line Missing". As you can see, the only difference here is that the file on the right does not have this blank line.
How can I make sublimerge ignore these blank lines? I've tried just removing all the blank lines in each file using search and replace in sublime and then running sublimerge, and that works.. but this isn't the optimal solution for me as I like having blank lines in between functions, etc.

Markdown: Problems with numbered list paragraphs containing code element

I created a README.md file on GitHub and there are some markdown problems I can't find a solution to.
When I enter this (The dots represent space signs):
Instructions:..
....1. First sentence..
....2. Second sentence..
........This is some code.
....3. Third sentence..
....4. Fourth sentence
It renders to this:
Instructions:
1. First sentence
2. Second sentence
This is some code.
3. Third sentence
4. Fourth sentence
How can I separate the code block from the numbered list?
I would also like to know how I can tell Markdown to ignore Markdown syntax so I don't have to use dots as a representation of space signs.
How about this?
Instructions:
1. First sentence
2. Second sentence
`This is some code.`
3. Third sentence
4. Fourth sentence
It wouldn't indent each point, however your example with the dots doesn't do it either.
If the spacing between Instructions: and the rest is not what you want, you can use the double space after it and on the two following lines.
UPDATE:
After a little fiddling, if you want to keep the numbering of the list and put some code that's relative to a single item on the list you should indent the code block.
Also, have a new line before the first element of the list seems to help.