Macro: How to suppress Texclipse error
up vote
0
down vote
favorite
For easy and versatile integration of pictures and graphics in my documents I found a nice solution in this post 'newcommand for pictures'.
Due to unorthodox order of begin{figure}
and end{figure}
in the code I always have Texclipse (pdflatex, oxygen) showing errors at these lines (see code below}: begin{figure} does not have matching end; at least one unbalanced begin-end
. However, the code compiles with fine output.
How can I avoid getting these error messages with the functionality of the code pointed out in the post? If the code is fine, how can I suppress the errors messages in Texclipse?
documentclass{article}
usepackage{graphicx}
usepackage{xparse}
% Between the ExplSyntaxOn the code is copied from
% https://tex.stackexchange.com/questions/242271/newcommand-for-pictures
ExplSyntaxOn
% the user level command
NewDocumentCommand{addpic}{m}
{
group_begin: % localize the changes to the variables
forthisdoc_pic:n { #1 }
group_end:
}
% the key-value interface
keys_define:nn { forthisdoc/pic }
{
placement .tl_set:N = l_forthisdoc_pic_placement_tl,
placement .initial:n = htp,
width .tl_set:N = l_forthisdoc_pic_width_tl,
width .initial:n = 1,
options .tl_set:N = l_forthisdoc_pic_options_tl,
image .tl_set:N = l_forthisdoc_pic_image_tl,
caption .tl_set:N = l_forthisdoc_pic_caption_tl,
shortcaption .tl_set:N = l_forthisdoc_pic_shortcaption_tl,
label .tl_set:N = l_forthisdoc_pic_label_tl,
}
% the main command
cs_new_protected:Nn forthisdoc_pic:n
{
% set the keys from the argument
keys_set:nn { forthisdoc/pic } { #1 }
% start the figure environment
__forthisdoc_start_figure:V l_forthisdoc_pic_placement_tl
centering
% include the image
__forthisdoc_pic_image:VVV
l_forthisdoc_pic_width_tl % the text width fraction
l_forthisdoc_pic_options_tl % other options
l_forthisdoc_pic_image_tl % the image name
% the caption
tl_if_empty:NTF l_forthisdoc_pic_shortcaption_tl
{
caption{l_forthisdoc_pic_caption_tl}
}
{
caption[l_forthisdoc_pic_shortcaption_tl]{l_forthisdoc_pic_caption_tl}
}
% the label
tl_if_empty:NF l_forthisdoc_pic_label_tl
{
label{l_forthisdoc_pic_label_tl}
}
% end the figure environment
end{figure}
}
% syntactic sugar: we want some token lists to be expanded before usage
cs_new_protected:Nn __forthisdoc_start_figure:n
{
begin{figure}[#1]
}
cs_generate_variant:Nn __forthisdoc_start_figure:n { V }
cs_new_protected:Nn __forthisdoc_pic_image:nnn
{
includegraphics[width=#1textwidth,#2]{#3}
}
cs_generate_variant:Nn __forthisdoc_pic_image:nnn { VVV }
ExplSyntaxOff
begin{document}
An example picture is shown in ref{label}.
addpic{
placement=bp,
width=0.2,
options={angle=90},
image=example-image-a,
caption=Rotated image,
label=label,
shortcaption=In the text the image is rotated!,
}
end{document}
macros includegraphics eclipse
add a comment |
up vote
0
down vote
favorite
For easy and versatile integration of pictures and graphics in my documents I found a nice solution in this post 'newcommand for pictures'.
Due to unorthodox order of begin{figure}
and end{figure}
in the code I always have Texclipse (pdflatex, oxygen) showing errors at these lines (see code below}: begin{figure} does not have matching end; at least one unbalanced begin-end
. However, the code compiles with fine output.
How can I avoid getting these error messages with the functionality of the code pointed out in the post? If the code is fine, how can I suppress the errors messages in Texclipse?
documentclass{article}
usepackage{graphicx}
usepackage{xparse}
% Between the ExplSyntaxOn the code is copied from
% https://tex.stackexchange.com/questions/242271/newcommand-for-pictures
ExplSyntaxOn
% the user level command
NewDocumentCommand{addpic}{m}
{
group_begin: % localize the changes to the variables
forthisdoc_pic:n { #1 }
group_end:
}
% the key-value interface
keys_define:nn { forthisdoc/pic }
{
placement .tl_set:N = l_forthisdoc_pic_placement_tl,
placement .initial:n = htp,
width .tl_set:N = l_forthisdoc_pic_width_tl,
width .initial:n = 1,
options .tl_set:N = l_forthisdoc_pic_options_tl,
image .tl_set:N = l_forthisdoc_pic_image_tl,
caption .tl_set:N = l_forthisdoc_pic_caption_tl,
shortcaption .tl_set:N = l_forthisdoc_pic_shortcaption_tl,
label .tl_set:N = l_forthisdoc_pic_label_tl,
}
% the main command
cs_new_protected:Nn forthisdoc_pic:n
{
% set the keys from the argument
keys_set:nn { forthisdoc/pic } { #1 }
% start the figure environment
__forthisdoc_start_figure:V l_forthisdoc_pic_placement_tl
centering
% include the image
__forthisdoc_pic_image:VVV
l_forthisdoc_pic_width_tl % the text width fraction
l_forthisdoc_pic_options_tl % other options
l_forthisdoc_pic_image_tl % the image name
% the caption
tl_if_empty:NTF l_forthisdoc_pic_shortcaption_tl
{
caption{l_forthisdoc_pic_caption_tl}
}
{
caption[l_forthisdoc_pic_shortcaption_tl]{l_forthisdoc_pic_caption_tl}
}
% the label
tl_if_empty:NF l_forthisdoc_pic_label_tl
{
label{l_forthisdoc_pic_label_tl}
}
% end the figure environment
end{figure}
}
% syntactic sugar: we want some token lists to be expanded before usage
cs_new_protected:Nn __forthisdoc_start_figure:n
{
begin{figure}[#1]
}
cs_generate_variant:Nn __forthisdoc_start_figure:n { V }
cs_new_protected:Nn __forthisdoc_pic_image:nnn
{
includegraphics[width=#1textwidth,#2]{#3}
}
cs_generate_variant:Nn __forthisdoc_pic_image:nnn { VVV }
ExplSyntaxOff
begin{document}
An example picture is shown in ref{label}.
addpic{
placement=bp,
width=0.2,
options={angle=90},
image=example-image-a,
caption=Rotated image,
label=label,
shortcaption=In the text the image is rotated!,
}
end{document}
macros includegraphics eclipse
1
just put the code inmypic.sty
and useusepackage{mypic}
in your docuemnt, then you can easily re-use in many documents and your editor will never see the code at all
– David Carlisle
Jul 6 at 6:54
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
For easy and versatile integration of pictures and graphics in my documents I found a nice solution in this post 'newcommand for pictures'.
Due to unorthodox order of begin{figure}
and end{figure}
in the code I always have Texclipse (pdflatex, oxygen) showing errors at these lines (see code below}: begin{figure} does not have matching end; at least one unbalanced begin-end
. However, the code compiles with fine output.
How can I avoid getting these error messages with the functionality of the code pointed out in the post? If the code is fine, how can I suppress the errors messages in Texclipse?
documentclass{article}
usepackage{graphicx}
usepackage{xparse}
% Between the ExplSyntaxOn the code is copied from
% https://tex.stackexchange.com/questions/242271/newcommand-for-pictures
ExplSyntaxOn
% the user level command
NewDocumentCommand{addpic}{m}
{
group_begin: % localize the changes to the variables
forthisdoc_pic:n { #1 }
group_end:
}
% the key-value interface
keys_define:nn { forthisdoc/pic }
{
placement .tl_set:N = l_forthisdoc_pic_placement_tl,
placement .initial:n = htp,
width .tl_set:N = l_forthisdoc_pic_width_tl,
width .initial:n = 1,
options .tl_set:N = l_forthisdoc_pic_options_tl,
image .tl_set:N = l_forthisdoc_pic_image_tl,
caption .tl_set:N = l_forthisdoc_pic_caption_tl,
shortcaption .tl_set:N = l_forthisdoc_pic_shortcaption_tl,
label .tl_set:N = l_forthisdoc_pic_label_tl,
}
% the main command
cs_new_protected:Nn forthisdoc_pic:n
{
% set the keys from the argument
keys_set:nn { forthisdoc/pic } { #1 }
% start the figure environment
__forthisdoc_start_figure:V l_forthisdoc_pic_placement_tl
centering
% include the image
__forthisdoc_pic_image:VVV
l_forthisdoc_pic_width_tl % the text width fraction
l_forthisdoc_pic_options_tl % other options
l_forthisdoc_pic_image_tl % the image name
% the caption
tl_if_empty:NTF l_forthisdoc_pic_shortcaption_tl
{
caption{l_forthisdoc_pic_caption_tl}
}
{
caption[l_forthisdoc_pic_shortcaption_tl]{l_forthisdoc_pic_caption_tl}
}
% the label
tl_if_empty:NF l_forthisdoc_pic_label_tl
{
label{l_forthisdoc_pic_label_tl}
}
% end the figure environment
end{figure}
}
% syntactic sugar: we want some token lists to be expanded before usage
cs_new_protected:Nn __forthisdoc_start_figure:n
{
begin{figure}[#1]
}
cs_generate_variant:Nn __forthisdoc_start_figure:n { V }
cs_new_protected:Nn __forthisdoc_pic_image:nnn
{
includegraphics[width=#1textwidth,#2]{#3}
}
cs_generate_variant:Nn __forthisdoc_pic_image:nnn { VVV }
ExplSyntaxOff
begin{document}
An example picture is shown in ref{label}.
addpic{
placement=bp,
width=0.2,
options={angle=90},
image=example-image-a,
caption=Rotated image,
label=label,
shortcaption=In the text the image is rotated!,
}
end{document}
macros includegraphics eclipse
For easy and versatile integration of pictures and graphics in my documents I found a nice solution in this post 'newcommand for pictures'.
Due to unorthodox order of begin{figure}
and end{figure}
in the code I always have Texclipse (pdflatex, oxygen) showing errors at these lines (see code below}: begin{figure} does not have matching end; at least one unbalanced begin-end
. However, the code compiles with fine output.
How can I avoid getting these error messages with the functionality of the code pointed out in the post? If the code is fine, how can I suppress the errors messages in Texclipse?
documentclass{article}
usepackage{graphicx}
usepackage{xparse}
% Between the ExplSyntaxOn the code is copied from
% https://tex.stackexchange.com/questions/242271/newcommand-for-pictures
ExplSyntaxOn
% the user level command
NewDocumentCommand{addpic}{m}
{
group_begin: % localize the changes to the variables
forthisdoc_pic:n { #1 }
group_end:
}
% the key-value interface
keys_define:nn { forthisdoc/pic }
{
placement .tl_set:N = l_forthisdoc_pic_placement_tl,
placement .initial:n = htp,
width .tl_set:N = l_forthisdoc_pic_width_tl,
width .initial:n = 1,
options .tl_set:N = l_forthisdoc_pic_options_tl,
image .tl_set:N = l_forthisdoc_pic_image_tl,
caption .tl_set:N = l_forthisdoc_pic_caption_tl,
shortcaption .tl_set:N = l_forthisdoc_pic_shortcaption_tl,
label .tl_set:N = l_forthisdoc_pic_label_tl,
}
% the main command
cs_new_protected:Nn forthisdoc_pic:n
{
% set the keys from the argument
keys_set:nn { forthisdoc/pic } { #1 }
% start the figure environment
__forthisdoc_start_figure:V l_forthisdoc_pic_placement_tl
centering
% include the image
__forthisdoc_pic_image:VVV
l_forthisdoc_pic_width_tl % the text width fraction
l_forthisdoc_pic_options_tl % other options
l_forthisdoc_pic_image_tl % the image name
% the caption
tl_if_empty:NTF l_forthisdoc_pic_shortcaption_tl
{
caption{l_forthisdoc_pic_caption_tl}
}
{
caption[l_forthisdoc_pic_shortcaption_tl]{l_forthisdoc_pic_caption_tl}
}
% the label
tl_if_empty:NF l_forthisdoc_pic_label_tl
{
label{l_forthisdoc_pic_label_tl}
}
% end the figure environment
end{figure}
}
% syntactic sugar: we want some token lists to be expanded before usage
cs_new_protected:Nn __forthisdoc_start_figure:n
{
begin{figure}[#1]
}
cs_generate_variant:Nn __forthisdoc_start_figure:n { V }
cs_new_protected:Nn __forthisdoc_pic_image:nnn
{
includegraphics[width=#1textwidth,#2]{#3}
}
cs_generate_variant:Nn __forthisdoc_pic_image:nnn { VVV }
ExplSyntaxOff
begin{document}
An example picture is shown in ref{label}.
addpic{
placement=bp,
width=0.2,
options={angle=90},
image=example-image-a,
caption=Rotated image,
label=label,
shortcaption=In the text the image is rotated!,
}
end{document}
macros includegraphics eclipse
macros includegraphics eclipse
asked Jul 6 at 6:49
Stefan Bollmann
335213
335213
1
just put the code inmypic.sty
and useusepackage{mypic}
in your docuemnt, then you can easily re-use in many documents and your editor will never see the code at all
– David Carlisle
Jul 6 at 6:54
add a comment |
1
just put the code inmypic.sty
and useusepackage{mypic}
in your docuemnt, then you can easily re-use in many documents and your editor will never see the code at all
– David Carlisle
Jul 6 at 6:54
1
1
just put the code in
mypic.sty
and use usepackage{mypic}
in your docuemnt, then you can easily re-use in many documents and your editor will never see the code at all– David Carlisle
Jul 6 at 6:54
just put the code in
mypic.sty
and use usepackage{mypic}
in your docuemnt, then you can easily re-use in many documents and your editor will never see the code at all– David Carlisle
Jul 6 at 6:54
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
As David Carlisle pointed out, putting the code into a *.sty file does it. E.g. a working example is
documentclass{article}
usepackage{addpic}
begin{document}
addpic{
width=0.3,
image=example-image,
caption={This is an example image, and a comma in the caption},
label=one,
}
end{document}
with the sty file containing
NeedsTeXFormat{LaTeX2e}
ProvidesPackage{addpic}[2018/12/03 addpic by tex.stackexchange example]
RequirePackage{graphicx}
RequirePackage{xparse}
% Between the ExplSyntaxOn the code is copied from
% https://tex.stackexchange.com/questions/242271/newcommand-for-pictures
ExplSyntaxOn
% the user level command
NewDocumentCommand{addpic}{m}
{
group_begin: % localize the changes to the variables
forthisdoc_pic:n { #1 }
group_end:
}
% the key-value interface
keys_define:nn { forthisdoc/pic }
{
placement .tl_set:N = l_forthisdoc_pic_placement_tl,
placement .initial:n = htp,
width .tl_set:N = l_forthisdoc_pic_width_tl,
width .initial:n = 1,
options .tl_set:N = l_forthisdoc_pic_options_tl,
image .tl_set:N = l_forthisdoc_pic_image_tl,
caption .tl_set:N = l_forthisdoc_pic_caption_tl,
shortcaption .tl_set:N = l_forthisdoc_pic_shortcaption_tl,
label .tl_set:N = l_forthisdoc_pic_label_tl,
}
% the main command
cs_new_protected:Nn forthisdoc_pic:n
{
% set the keys from the argument
keys_set:nn { forthisdoc/pic } { #1 }
% start the figure environment
__forthisdoc_start_figure:V l_forthisdoc_pic_placement_tl
centering
% include the image
__forthisdoc_pic_image:VVV
l_forthisdoc_pic_width_tl % the text width fraction
l_forthisdoc_pic_options_tl % other options
l_forthisdoc_pic_image_tl % the image name
% the caption
tl_if_empty:NTF l_forthisdoc_pic_shortcaption_tl
{
caption{l_forthisdoc_pic_caption_tl}
}
{
caption[l_forthisdoc_pic_shortcaption_tl]{l_forthisdoc_pic_caption_tl}
}
% the label
tl_if_empty:NF l_forthisdoc_pic_label_tl
{
label{l_forthisdoc_pic_label_tl}
}
% end the figure environment
end{figure}
}
% syntactic sugar: we want some token lists to be expanded before usage
cs_new_protected:Nn __forthisdoc_start_figure:n
{
begin{figure}[#1]
}
cs_generate_variant:Nn __forthisdoc_start_figure:n { V }
cs_new_protected:Nn __forthisdoc_pic_image:nnn
{
includegraphics[width=#1textwidth,#2]{#3}
}
cs_generate_variant:Nn __forthisdoc_pic_image:nnn { VVV }
ExplSyntaxOff
Here is some help for a good place of the sty file.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
As David Carlisle pointed out, putting the code into a *.sty file does it. E.g. a working example is
documentclass{article}
usepackage{addpic}
begin{document}
addpic{
width=0.3,
image=example-image,
caption={This is an example image, and a comma in the caption},
label=one,
}
end{document}
with the sty file containing
NeedsTeXFormat{LaTeX2e}
ProvidesPackage{addpic}[2018/12/03 addpic by tex.stackexchange example]
RequirePackage{graphicx}
RequirePackage{xparse}
% Between the ExplSyntaxOn the code is copied from
% https://tex.stackexchange.com/questions/242271/newcommand-for-pictures
ExplSyntaxOn
% the user level command
NewDocumentCommand{addpic}{m}
{
group_begin: % localize the changes to the variables
forthisdoc_pic:n { #1 }
group_end:
}
% the key-value interface
keys_define:nn { forthisdoc/pic }
{
placement .tl_set:N = l_forthisdoc_pic_placement_tl,
placement .initial:n = htp,
width .tl_set:N = l_forthisdoc_pic_width_tl,
width .initial:n = 1,
options .tl_set:N = l_forthisdoc_pic_options_tl,
image .tl_set:N = l_forthisdoc_pic_image_tl,
caption .tl_set:N = l_forthisdoc_pic_caption_tl,
shortcaption .tl_set:N = l_forthisdoc_pic_shortcaption_tl,
label .tl_set:N = l_forthisdoc_pic_label_tl,
}
% the main command
cs_new_protected:Nn forthisdoc_pic:n
{
% set the keys from the argument
keys_set:nn { forthisdoc/pic } { #1 }
% start the figure environment
__forthisdoc_start_figure:V l_forthisdoc_pic_placement_tl
centering
% include the image
__forthisdoc_pic_image:VVV
l_forthisdoc_pic_width_tl % the text width fraction
l_forthisdoc_pic_options_tl % other options
l_forthisdoc_pic_image_tl % the image name
% the caption
tl_if_empty:NTF l_forthisdoc_pic_shortcaption_tl
{
caption{l_forthisdoc_pic_caption_tl}
}
{
caption[l_forthisdoc_pic_shortcaption_tl]{l_forthisdoc_pic_caption_tl}
}
% the label
tl_if_empty:NF l_forthisdoc_pic_label_tl
{
label{l_forthisdoc_pic_label_tl}
}
% end the figure environment
end{figure}
}
% syntactic sugar: we want some token lists to be expanded before usage
cs_new_protected:Nn __forthisdoc_start_figure:n
{
begin{figure}[#1]
}
cs_generate_variant:Nn __forthisdoc_start_figure:n { V }
cs_new_protected:Nn __forthisdoc_pic_image:nnn
{
includegraphics[width=#1textwidth,#2]{#3}
}
cs_generate_variant:Nn __forthisdoc_pic_image:nnn { VVV }
ExplSyntaxOff
Here is some help for a good place of the sty file.
add a comment |
up vote
0
down vote
accepted
As David Carlisle pointed out, putting the code into a *.sty file does it. E.g. a working example is
documentclass{article}
usepackage{addpic}
begin{document}
addpic{
width=0.3,
image=example-image,
caption={This is an example image, and a comma in the caption},
label=one,
}
end{document}
with the sty file containing
NeedsTeXFormat{LaTeX2e}
ProvidesPackage{addpic}[2018/12/03 addpic by tex.stackexchange example]
RequirePackage{graphicx}
RequirePackage{xparse}
% Between the ExplSyntaxOn the code is copied from
% https://tex.stackexchange.com/questions/242271/newcommand-for-pictures
ExplSyntaxOn
% the user level command
NewDocumentCommand{addpic}{m}
{
group_begin: % localize the changes to the variables
forthisdoc_pic:n { #1 }
group_end:
}
% the key-value interface
keys_define:nn { forthisdoc/pic }
{
placement .tl_set:N = l_forthisdoc_pic_placement_tl,
placement .initial:n = htp,
width .tl_set:N = l_forthisdoc_pic_width_tl,
width .initial:n = 1,
options .tl_set:N = l_forthisdoc_pic_options_tl,
image .tl_set:N = l_forthisdoc_pic_image_tl,
caption .tl_set:N = l_forthisdoc_pic_caption_tl,
shortcaption .tl_set:N = l_forthisdoc_pic_shortcaption_tl,
label .tl_set:N = l_forthisdoc_pic_label_tl,
}
% the main command
cs_new_protected:Nn forthisdoc_pic:n
{
% set the keys from the argument
keys_set:nn { forthisdoc/pic } { #1 }
% start the figure environment
__forthisdoc_start_figure:V l_forthisdoc_pic_placement_tl
centering
% include the image
__forthisdoc_pic_image:VVV
l_forthisdoc_pic_width_tl % the text width fraction
l_forthisdoc_pic_options_tl % other options
l_forthisdoc_pic_image_tl % the image name
% the caption
tl_if_empty:NTF l_forthisdoc_pic_shortcaption_tl
{
caption{l_forthisdoc_pic_caption_tl}
}
{
caption[l_forthisdoc_pic_shortcaption_tl]{l_forthisdoc_pic_caption_tl}
}
% the label
tl_if_empty:NF l_forthisdoc_pic_label_tl
{
label{l_forthisdoc_pic_label_tl}
}
% end the figure environment
end{figure}
}
% syntactic sugar: we want some token lists to be expanded before usage
cs_new_protected:Nn __forthisdoc_start_figure:n
{
begin{figure}[#1]
}
cs_generate_variant:Nn __forthisdoc_start_figure:n { V }
cs_new_protected:Nn __forthisdoc_pic_image:nnn
{
includegraphics[width=#1textwidth,#2]{#3}
}
cs_generate_variant:Nn __forthisdoc_pic_image:nnn { VVV }
ExplSyntaxOff
Here is some help for a good place of the sty file.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
As David Carlisle pointed out, putting the code into a *.sty file does it. E.g. a working example is
documentclass{article}
usepackage{addpic}
begin{document}
addpic{
width=0.3,
image=example-image,
caption={This is an example image, and a comma in the caption},
label=one,
}
end{document}
with the sty file containing
NeedsTeXFormat{LaTeX2e}
ProvidesPackage{addpic}[2018/12/03 addpic by tex.stackexchange example]
RequirePackage{graphicx}
RequirePackage{xparse}
% Between the ExplSyntaxOn the code is copied from
% https://tex.stackexchange.com/questions/242271/newcommand-for-pictures
ExplSyntaxOn
% the user level command
NewDocumentCommand{addpic}{m}
{
group_begin: % localize the changes to the variables
forthisdoc_pic:n { #1 }
group_end:
}
% the key-value interface
keys_define:nn { forthisdoc/pic }
{
placement .tl_set:N = l_forthisdoc_pic_placement_tl,
placement .initial:n = htp,
width .tl_set:N = l_forthisdoc_pic_width_tl,
width .initial:n = 1,
options .tl_set:N = l_forthisdoc_pic_options_tl,
image .tl_set:N = l_forthisdoc_pic_image_tl,
caption .tl_set:N = l_forthisdoc_pic_caption_tl,
shortcaption .tl_set:N = l_forthisdoc_pic_shortcaption_tl,
label .tl_set:N = l_forthisdoc_pic_label_tl,
}
% the main command
cs_new_protected:Nn forthisdoc_pic:n
{
% set the keys from the argument
keys_set:nn { forthisdoc/pic } { #1 }
% start the figure environment
__forthisdoc_start_figure:V l_forthisdoc_pic_placement_tl
centering
% include the image
__forthisdoc_pic_image:VVV
l_forthisdoc_pic_width_tl % the text width fraction
l_forthisdoc_pic_options_tl % other options
l_forthisdoc_pic_image_tl % the image name
% the caption
tl_if_empty:NTF l_forthisdoc_pic_shortcaption_tl
{
caption{l_forthisdoc_pic_caption_tl}
}
{
caption[l_forthisdoc_pic_shortcaption_tl]{l_forthisdoc_pic_caption_tl}
}
% the label
tl_if_empty:NF l_forthisdoc_pic_label_tl
{
label{l_forthisdoc_pic_label_tl}
}
% end the figure environment
end{figure}
}
% syntactic sugar: we want some token lists to be expanded before usage
cs_new_protected:Nn __forthisdoc_start_figure:n
{
begin{figure}[#1]
}
cs_generate_variant:Nn __forthisdoc_start_figure:n { V }
cs_new_protected:Nn __forthisdoc_pic_image:nnn
{
includegraphics[width=#1textwidth,#2]{#3}
}
cs_generate_variant:Nn __forthisdoc_pic_image:nnn { VVV }
ExplSyntaxOff
Here is some help for a good place of the sty file.
As David Carlisle pointed out, putting the code into a *.sty file does it. E.g. a working example is
documentclass{article}
usepackage{addpic}
begin{document}
addpic{
width=0.3,
image=example-image,
caption={This is an example image, and a comma in the caption},
label=one,
}
end{document}
with the sty file containing
NeedsTeXFormat{LaTeX2e}
ProvidesPackage{addpic}[2018/12/03 addpic by tex.stackexchange example]
RequirePackage{graphicx}
RequirePackage{xparse}
% Between the ExplSyntaxOn the code is copied from
% https://tex.stackexchange.com/questions/242271/newcommand-for-pictures
ExplSyntaxOn
% the user level command
NewDocumentCommand{addpic}{m}
{
group_begin: % localize the changes to the variables
forthisdoc_pic:n { #1 }
group_end:
}
% the key-value interface
keys_define:nn { forthisdoc/pic }
{
placement .tl_set:N = l_forthisdoc_pic_placement_tl,
placement .initial:n = htp,
width .tl_set:N = l_forthisdoc_pic_width_tl,
width .initial:n = 1,
options .tl_set:N = l_forthisdoc_pic_options_tl,
image .tl_set:N = l_forthisdoc_pic_image_tl,
caption .tl_set:N = l_forthisdoc_pic_caption_tl,
shortcaption .tl_set:N = l_forthisdoc_pic_shortcaption_tl,
label .tl_set:N = l_forthisdoc_pic_label_tl,
}
% the main command
cs_new_protected:Nn forthisdoc_pic:n
{
% set the keys from the argument
keys_set:nn { forthisdoc/pic } { #1 }
% start the figure environment
__forthisdoc_start_figure:V l_forthisdoc_pic_placement_tl
centering
% include the image
__forthisdoc_pic_image:VVV
l_forthisdoc_pic_width_tl % the text width fraction
l_forthisdoc_pic_options_tl % other options
l_forthisdoc_pic_image_tl % the image name
% the caption
tl_if_empty:NTF l_forthisdoc_pic_shortcaption_tl
{
caption{l_forthisdoc_pic_caption_tl}
}
{
caption[l_forthisdoc_pic_shortcaption_tl]{l_forthisdoc_pic_caption_tl}
}
% the label
tl_if_empty:NF l_forthisdoc_pic_label_tl
{
label{l_forthisdoc_pic_label_tl}
}
% end the figure environment
end{figure}
}
% syntactic sugar: we want some token lists to be expanded before usage
cs_new_protected:Nn __forthisdoc_start_figure:n
{
begin{figure}[#1]
}
cs_generate_variant:Nn __forthisdoc_start_figure:n { V }
cs_new_protected:Nn __forthisdoc_pic_image:nnn
{
includegraphics[width=#1textwidth,#2]{#3}
}
cs_generate_variant:Nn __forthisdoc_pic_image:nnn { VVV }
ExplSyntaxOff
Here is some help for a good place of the sty file.
answered Dec 3 at 18:37
Stefan Bollmann
335213
335213
add a comment |
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f439467%2fmacro-how-to-suppress-texclipse-error%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
just put the code in
mypic.sty
and useusepackage{mypic}
in your docuemnt, then you can easily re-use in many documents and your editor will never see the code at all– David Carlisle
Jul 6 at 6:54